4.0.0
Simple ExtensionSimpleExtPlugin
allows creating simple delimited extensions, for example:
+this is text surrounded by `+`+
final Markwon markwon = Markwon.builder(this)
.usePlugin(SimpleExtPlugin.create(plugin -> plugin
// +sometext+
.addExtension(1, '+', new SpanFactory() {
@Override
public Object getSpans(@NonNull MarkwonConfiguration configuration, @NonNull RenderProps props) {
return new EmphasisSpan();
}
})
.build();
or
final Markwon markwon = Markwon.builder(this)
.usePlugin(SimpleExtPlugin.create())
.usePlugin(new AbstractMarkwonPlugin() {
@Override
public void configure(@NonNull Registry registry) {
registry.require(SimpleExtPlugin.class, new Action<SimpleExtPlugin>() {
@Override
public void apply(@NonNull SimpleExtPlugin plugin) {
plugin.addExtension(1, '+', new SpanFactory() {
@Override
public Object getSpans(@NonNull MarkwonConfiguration configuration, @NonNull RenderProps props) {
return new EmphasisSpan();
}
})
}
});
}
})
.build();
If opening and closing characters are different another method can be used:
plugin.addExtension(
/*length*/2,
/*openingCharacter*/'@',
/*closingCharacter*/'$',
/*spanFactory*/(configuration, props) -> new ForegroundColorSpan(Color.RED))))
This extension will be applied to a text like this:
@@we are inside different delimiter characters$$
WARNING
Space character cannot be used as a delimiter (from either side). So,
plugin.addExtension(1, '@', ' ', /*spanFactory*/);
won't work for @some-text
text