Inline Parser 4.2.0

Experimental commonmark-java inline parser that allows customizing core features and/or extend with own.

TIP

Since 4.3.0 there is also MarkwonInlineParserPlugin which can be used to allow other plugins to customize inline parser

final Markwon markwon = Markwon.builder(this)
        .usePlugin(MarkwonInlineParserPlugin.create())
        .build();

Usage of internal classes:

import org.commonmark.internal.Bracket;
import org.commonmark.internal.Delimiter;
import org.commonmark.internal.util.Escaping;
import org.commonmark.internal.util.Html5Entities;
import org.commonmark.internal.util.LinkScanner;
import org.commonmark.internal.util.Parsing;
import org.commonmark.internal.inline.AsteriskDelimiterProcessor;
import org.commonmark.internal.inline.UnderscoreDelimiterProcessor;

// all default (like current commonmark-java InlineParserImpl) 
final InlineParserFactory factory = MarkwonInlineParser.factoryBuilder()
        .build();
// disable images (current markdown images will be considered as links):
final InlineParserFactory factory = MarkwonInlineParser.factoryBuilder()
        .excludeInlineProcessor(BangInlineProcessor.class)
        .build();
// disable core delimiter processors for `*`|`_` and `**`|`__`
final InlineParserFactory factory = MarkwonInlineParser.factoryBuilder()
        .excludeDelimiterProcessor(AsteriskDelimiterProcessor.class)
        .excludeDelimiterProcessor(UnderscoreDelimiterProcessor.class)
        .build();
// disable _all_ markdown inlines except for links (open and close bracket handling `[` & `]`)
final InlineParserFactory inlineParserFactory = MarkwonInlineParser.factoryBuilderNoDefaults()
        // note that there is no `includeDefaults` method call
        .referencesEnabled(true)
        .addInlineProcessor(new OpenBracketInlineProcessor())
        .addInlineProcessor(new CloseBracketInlineProcessor())
        .build();

To use custom InlineParser:

final Markwon markwon = Markwon.builder(this)
        .usePlugin(new AbstractMarkwonPlugin() {
            @Override
            public void configureParser(@NonNull Parser.Builder builder) {
                builder.inlineParserFactory(inlineParserFactory);
            }
        })
        .build();

The list of available inline processors:

  • AutolinkInlineProcessor (< => <me@mydoma.in>)
  • BackslashInlineProcessor (\\)
  • BackticksInlineProcessor (` => `code`)
  • BangInlineProcessor (! => ![alt](#src))
  • CloseBracketInlineProcessor (] => [link](#href), ![alt](#src))
  • EntityInlineProcessor (& => &amp;)
  • HtmlInlineProcessor (< => <html></html>)
  • NewLineInlineProcessor (\n)
  • OpenBracketInlineProcessor ([ => [link](#href))
Last Updated: 3/18/2020, 2:20:58 PM