2.8 KiB
Core plugin
Since with introduction of plugins, Markwon core functionality was moved to a dedicated plugin.
CorePlugin.create();
Node visitors
CorePlugin registers these commonmark-java node visitors:
TextStrongEmphasisEmphasisBlockQuoteCodeFencedCodeBlockIndentedCodeBlockBulletListOrderedListListItemThematicBreakHeadingSoftLineBreakHardLineBreakParagraphLink
Span factories
CorePlugin adds these SpanFactorys:
StrongEmphasisEmphasisBlockQuoteCodeFencedCodeBlockIndentedCodeBlockListItemHeadingLinkThematicBreak
:::tip
By default CorePlugin does not register a Paragraph SpanFactory but
this can be done in your custom plugin:
Markwon.builder(context)
.usePlugin(new AbstractMarkwonPlugin() {
@Override
public void configureSpansFactory(@NonNull MarkwonSpansFactory.Builder builder) {
builder.setFactory(Paragraph.class, (configuration, props) ->
new ForegroundColorSpan(Color.RED));
}
})
:::
Props
These props are exported by CorePlugin and can be found in CoreProps:
Prop<ListItemType> LIST_ITEM_TYPE(BULLET | ORDERED)Prop<Integer> BULLET_LIST_ITEM_LEVELProp<Integer> ORDERED_LIST_ITEM_NUMBERProp<Integer> HEADING_LEVELProp<String> LINK_DESTINATIONProp<Boolean> PARAGRAPH_IS_IN_TIGHT_LIST
:::warning List item type
Before Markwon had 2 distinct lists (bullet and ordered).
Since a single SpanFactory is used, which internally checks
for Prop<ListItemType> LIST_ITEM_TYPE.
Beware of this if you would like to override only one of the list types. This is
done to correspond to commonmark-java implementation.
:::
:::tip Soft line break Since Markwon core does not give an option to insert a new line when there is a soft line break in markdown. Instead a custom plugin can be used:
final Markwon markwon = Markwon.builder(this)
.usePlugin(new AbstractMarkwonPlugin() {
@Override
public void configureVisitor(@NonNull MarkwonVisitor.Builder builder) {
builder.on(SoftLineBreak.class, (visitor, softLineBreak) ->
visitor.forceNewLine());
}
})
.build();
:::
:::warning
Please note that CorePlugin will implicitly set a LinkMovementMethod on a TextView
if one is not present. If you wish to customize a MovementMethod that is used, apply
one manually to a TextView (before applying markdown) or use the MovementMethodPlugin
which accepts a MovementMethod as an argument.
:::