Markdown images size is also resolved via ImageSizeResolver
This commit is contained in:
parent
b1587f9a46
commit
062a1251cb
@ -299,9 +299,8 @@ Underscores (`_`)
|
||||
|
||||
## Applications using Markwon
|
||||
|
||||
<a href="https://play.google.com/store/apps/details?id=com.rgiskard.fairnote">
|
||||
<img src="https://lh3.googleusercontent.com/9IGNiS66dweMOEm7F5JzzKpF8ggys5h7kxYRlbXWZIbbA5T1Vqp7xrLdW90V1VTMPw=s360" width="128px"><br>
|
||||
FairNote Notepad</a>
|
||||
* [FairNote Notepad](https://play.google.com/store/apps/details?id=com.rgiskard.fairnote)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
|
@ -3,8 +3,8 @@ package ru.noties.markwon;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import ru.noties.markwon.renderer.html.ImageSizeResolver;
|
||||
import ru.noties.markwon.renderer.html.ImageSizeResolverDef;
|
||||
import ru.noties.markwon.renderer.ImageSizeResolver;
|
||||
import ru.noties.markwon.renderer.ImageSizeResolverDef;
|
||||
import ru.noties.markwon.renderer.html.SpannableHtmlParser;
|
||||
import ru.noties.markwon.spans.AsyncDrawable;
|
||||
import ru.noties.markwon.spans.LinkSpan;
|
||||
@ -30,6 +30,7 @@ public class SpannableConfiguration {
|
||||
private final LinkSpan.Resolver linkResolver;
|
||||
private final UrlProcessor urlProcessor;
|
||||
private final SpannableHtmlParser htmlParser;
|
||||
private final ImageSizeResolver imageSizeResolver;
|
||||
|
||||
private SpannableConfiguration(@NonNull Builder builder) {
|
||||
this.theme = builder.theme;
|
||||
@ -38,6 +39,7 @@ public class SpannableConfiguration {
|
||||
this.linkResolver = builder.linkResolver;
|
||||
this.urlProcessor = builder.urlProcessor;
|
||||
this.htmlParser = builder.htmlParser;
|
||||
this.imageSizeResolver = builder.imageSizeResolver;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@ -70,6 +72,11 @@ public class SpannableConfiguration {
|
||||
return htmlParser;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ImageSizeResolver imageSizeResolver() {
|
||||
return imageSizeResolver;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static class Builder {
|
||||
|
||||
@ -154,12 +161,11 @@ public class SpannableConfiguration {
|
||||
urlProcessor = new UrlProcessorNoOp();
|
||||
}
|
||||
|
||||
if (imageSizeResolver == null) {
|
||||
imageSizeResolver = new ImageSizeResolverDef();
|
||||
}
|
||||
|
||||
if (htmlParser == null) {
|
||||
|
||||
if (imageSizeResolver == null) {
|
||||
imageSizeResolver = new ImageSizeResolverDef();
|
||||
}
|
||||
|
||||
htmlParser = SpannableHtmlParser.create(theme, asyncDrawableLoader, urlProcessor, linkResolver, imageSizeResolver);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package ru.noties.markwon.renderer.html;
|
||||
package ru.noties.markwon.renderer;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
@ -34,4 +34,12 @@ public class ImageSize {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ImageSize{" +
|
||||
"width=" + width +
|
||||
", height=" + height +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package ru.noties.markwon.renderer.html;
|
||||
package ru.noties.markwon.renderer;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.support.annotation.NonNull;
|
@ -1,4 +1,4 @@
|
||||
package ru.noties.markwon.renderer.html;
|
||||
package ru.noties.markwon.renderer;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.support.annotation.NonNull;
|
@ -438,7 +438,9 @@ public class SpannableMarkdownVisitor extends AbstractVisitor {
|
||||
configuration.theme(),
|
||||
new AsyncDrawable(
|
||||
destination,
|
||||
configuration.asyncDrawableLoader()
|
||||
configuration.asyncDrawableLoader(),
|
||||
configuration.imageSizeResolver(),
|
||||
null
|
||||
),
|
||||
AsyncDrawableSpan.ALIGN_BOTTOM,
|
||||
link
|
||||
|
@ -11,6 +11,8 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import ru.noties.markwon.UrlProcessor;
|
||||
import ru.noties.markwon.renderer.ImageSize;
|
||||
import ru.noties.markwon.renderer.ImageSizeResolver;
|
||||
import ru.noties.markwon.spans.AsyncDrawable;
|
||||
import ru.noties.markwon.spans.AsyncDrawableSpan;
|
||||
import ru.noties.markwon.spans.SpannableTheme;
|
||||
|
@ -13,6 +13,8 @@ import java.util.Map;
|
||||
import ru.noties.markwon.LinkResolverDef;
|
||||
import ru.noties.markwon.UrlProcessor;
|
||||
import ru.noties.markwon.UrlProcessorNoOp;
|
||||
import ru.noties.markwon.renderer.ImageSizeResolver;
|
||||
import ru.noties.markwon.renderer.ImageSizeResolverDef;
|
||||
import ru.noties.markwon.spans.AsyncDrawable;
|
||||
import ru.noties.markwon.spans.LinkSpan;
|
||||
import ru.noties.markwon.spans.SpannableTheme;
|
||||
|
@ -10,8 +10,8 @@ import android.support.annotation.IntRange;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import ru.noties.markwon.renderer.html.ImageSize;
|
||||
import ru.noties.markwon.renderer.html.ImageSizeResolver;
|
||||
import ru.noties.markwon.renderer.ImageSize;
|
||||
import ru.noties.markwon.renderer.ImageSizeResolver;
|
||||
|
||||
public class AsyncDrawable extends Drawable {
|
||||
|
||||
@ -33,6 +33,10 @@ public class AsyncDrawable extends Drawable {
|
||||
private int canvasWidth;
|
||||
private float textSize;
|
||||
|
||||
/**
|
||||
* @deprecated 1.0.6 markdown images are also processed with {@link ImageSizeResolver}
|
||||
*/
|
||||
@Deprecated
|
||||
public AsyncDrawable(@NonNull String destination, @NonNull Loader loader) {
|
||||
this(destination, loader, null, null);
|
||||
}
|
||||
@ -176,8 +180,7 @@ public class AsyncDrawable extends Drawable {
|
||||
|
||||
final Rect rect;
|
||||
|
||||
if (imageSizeResolver == null
|
||||
|| imageSize == null) {
|
||||
if (imageSizeResolver == null) {
|
||||
|
||||
// @since 1.0.5
|
||||
final Rect bounds = result.getBounds();
|
||||
|
Loading…
x
Reference in New Issue
Block a user