Add HtmlConfigure for HtmlPlugin
This commit is contained in:
parent
4b918bf094
commit
79b99abb24
@ -27,11 +27,29 @@ import ru.noties.markwon.html.tag.UnderlineHandler;
|
||||
*/
|
||||
public class HtmlPlugin extends AbstractMarkwonPlugin {
|
||||
|
||||
/**
|
||||
* @see #create(HtmlConfigure)
|
||||
* @since 4.0.0-SNAPSHOT
|
||||
*/
|
||||
public interface HtmlConfigure {
|
||||
void configureHtml(@NonNull HtmlPlugin plugin);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static HtmlPlugin create() {
|
||||
return new HtmlPlugin();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.0.0-SNAPSHOT
|
||||
*/
|
||||
@NonNull
|
||||
public static HtmlPlugin create(@NonNull HtmlConfigure configure) {
|
||||
final HtmlPlugin plugin = create();
|
||||
configure.configureHtml(plugin);
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public static final float SCRIPT_DEF_TEXT_SIZE_RATIO = .75F;
|
||||
|
||||
private final MarkwonHtmlRendererImpl.Builder builder;
|
||||
|
@ -6,20 +6,33 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.Layout;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.AlignmentSpan;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.commonmark.node.Heading;
|
||||
import org.commonmark.node.Paragraph;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import ru.noties.markwon.AbstractMarkwonPlugin;
|
||||
import ru.noties.markwon.Markwon;
|
||||
import ru.noties.markwon.MarkwonConfiguration;
|
||||
import ru.noties.markwon.MarkwonPlugin;
|
||||
import ru.noties.markwon.MarkwonSpansFactory;
|
||||
import ru.noties.markwon.MarkwonVisitor;
|
||||
import ru.noties.markwon.RenderProps;
|
||||
import ru.noties.markwon.core.MarkwonTheme;
|
||||
import ru.noties.markwon.html.HtmlPlugin;
|
||||
import ru.noties.markwon.html.HtmlTag;
|
||||
import ru.noties.markwon.html.tag.SimpleTagHandler;
|
||||
import ru.noties.markwon.image.ImageItem;
|
||||
import ru.noties.markwon.image.ImagesPlugin;
|
||||
import ru.noties.markwon.image.SchemeHandler;
|
||||
import ru.noties.markwon.image.network.NetworkSchemeHandler;
|
||||
import ru.noties.markwon.movement.MovementMethodPlugin;
|
||||
|
||||
public class BasicPluginsActivity extends Activity {
|
||||
@ -42,6 +55,8 @@ public class BasicPluginsActivity extends Activity {
|
||||
step_4();
|
||||
|
||||
step_5();
|
||||
|
||||
step_6();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,30 +182,67 @@ public class BasicPluginsActivity extends Activity {
|
||||
final String markdown = "";
|
||||
|
||||
final Markwon markwon = Markwon.builder(this)
|
||||
// .usePlugin(ImagesPlugin.create(this))
|
||||
// .usePlugin(new AbstractMarkwonPlugin() {
|
||||
// @Override
|
||||
// public void configureImages(@NonNull AsyncDrawableLoader.Builder builder) {
|
||||
// // we can have a custom SchemeHandler
|
||||
// // here we will just use networkSchemeHandler to redirect call
|
||||
// builder.addSchemeHandler("myownscheme", new SchemeHandler() {
|
||||
//
|
||||
// final NetworkSchemeHandler networkSchemeHandler = NetworkSchemeHandler.create();
|
||||
//
|
||||
// @Nullable
|
||||
// @Override
|
||||
// public ImageItem handle(@NonNull String raw, @NonNull Uri uri) {
|
||||
// raw = raw.replace("myownscheme", "https");
|
||||
// return networkSchemeHandler.handle(raw, Uri.parse(raw));
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// })
|
||||
.usePlugin(ImagesPlugin.create())
|
||||
.usePlugin(new AbstractMarkwonPlugin() {
|
||||
@Override
|
||||
public void configure(@NonNull Registry registry) {
|
||||
|
||||
// use registry.require to obtain a plugin, does also
|
||||
// a runtime validation if this plugin is registered
|
||||
registry.require(ImagesPlugin.class, plugin -> plugin.addSchemeHandler(new SchemeHandler() {
|
||||
|
||||
// it's a sample only, most likely you won't need to
|
||||
// use existing scheme-handler, this for demonstration purposes only
|
||||
final NetworkSchemeHandler handler = NetworkSchemeHandler.create();
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ImageItem handle(@NonNull String raw, @NonNull Uri uri) {
|
||||
final String url = raw.replace("myownscheme", "https");
|
||||
return handler.handle(url, Uri.parse(url));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Collection<String> supportedSchemes() {
|
||||
return Collections.singleton("myownscheme");
|
||||
}
|
||||
}));
|
||||
}
|
||||
})
|
||||
// or we can init plugin with this factory method
|
||||
// .usePlugin(ImagesPlugin.create(plugin -> {
|
||||
// plugin.addSchemeHandler(/**/)
|
||||
// }))
|
||||
.build();
|
||||
|
||||
markwon.setMarkdown(textView, markdown);
|
||||
}
|
||||
|
||||
public void step_6() {
|
||||
|
||||
final Markwon markwon = Markwon.builder(this)
|
||||
.usePlugin(HtmlPlugin.create())
|
||||
.usePlugin(new AbstractMarkwonPlugin() {
|
||||
@Override
|
||||
public void configure(@NonNull Registry registry) {
|
||||
registry.require(HtmlPlugin.class, plugin -> plugin.addHandler(new SimpleTagHandler() {
|
||||
@Override
|
||||
public Object getSpans(@NonNull MarkwonConfiguration configuration, @NonNull RenderProps renderProps, @NonNull HtmlTag tag) {
|
||||
return new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Collection<String> supportedTags() {
|
||||
return Collections.singleton("center");
|
||||
}
|
||||
}));
|
||||
}
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
// text lifecycle (after/before)
|
||||
// rendering lifecycle (before/after)
|
||||
// renderProps
|
||||
|
@ -86,8 +86,8 @@ public class RecyclerActivity extends Activity {
|
||||
// .addSchemeHandler(OkHttpNetworkSchemeHandler.create())
|
||||
// .addMediaDecoder(SvgMediaDecoder.create());
|
||||
// }))
|
||||
// .usePlugin(PicassoImagesPlugin.create(context))
|
||||
.usePlugin(GlideImagesPlugin.create(context))
|
||||
.usePlugin(PicassoImagesPlugin.create(context))
|
||||
// .usePlugin(GlideImagesPlugin.create(context))
|
||||
// important to use TableEntryPlugin instead of TablePlugin
|
||||
.usePlugin(TableEntryPlugin.create(context))
|
||||
.usePlugin(HtmlPlugin.create())
|
||||
|
Loading…
x
Reference in New Issue
Block a user