Class Parser.Builder
- java.lang.Object
-
- org.commonmark.parser.Parser.Builder
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<BlockParserFactory>blockParserFactoriesprivate java.util.List<DelimiterProcessor>delimiterProcessorsprivate java.util.Set<java.lang.Class<? extends Block>>enabledBlockTypesprivate IncludeSourceSpansincludeSourceSpansprivate InlineParserFactoryinlineParserFactoryprivate java.util.List<PostProcessor>postProcessors
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Parserbuild()Parser.BuildercustomBlockParserFactory(BlockParserFactory blockParserFactory)Adds a custom block parser factory.Parser.BuildercustomDelimiterProcessor(DelimiterProcessor delimiterProcessor)Adds a custom delimiter processor.Parser.BuilderenabledBlockTypes(java.util.Set<java.lang.Class<? extends Block>> enabledBlockTypes)Describe the list of markdown features the parser will recognize and parse.Parser.Builderextensions(java.lang.Iterable<? extends Extension> extensions)private InlineParserFactorygetInlineParserFactory()Parser.BuilderincludeSourceSpans(IncludeSourceSpans includeSourceSpans)Whether to calculateSourceSpanforNode.Parser.BuilderinlineParserFactory(InlineParserFactory inlineParserFactory)Overrides the parser used for inline markdown processing.Parser.BuilderpostProcessor(PostProcessor postProcessor)
-
-
-
Field Detail
-
blockParserFactories
private final java.util.List<BlockParserFactory> blockParserFactories
-
delimiterProcessors
private final java.util.List<DelimiterProcessor> delimiterProcessors
-
postProcessors
private final java.util.List<PostProcessor> postProcessors
-
enabledBlockTypes
private java.util.Set<java.lang.Class<? extends Block>> enabledBlockTypes
-
inlineParserFactory
private InlineParserFactory inlineParserFactory
-
includeSourceSpans
private IncludeSourceSpans includeSourceSpans
-
-
Method Detail
-
extensions
public Parser.Builder extensions(java.lang.Iterable<? extends Extension> extensions)
- Parameters:
extensions- extensions to use on this parser- Returns:
this
-
enabledBlockTypes
public Parser.Builder enabledBlockTypes(java.util.Set<java.lang.Class<? extends Block>> enabledBlockTypes)
Describe the list of markdown features the parser will recognize and parse.By default, CommonMark will recognize and parse the following set of "block" elements:
Heading(#)HtmlBlock(<html></html>)ThematicBreak(Horizontal Rule) (---)FencedCodeBlock(```)IndentedCodeBlockBlockQuote(>)ListBlock(Ordered / Unordered List) (1. / *)
To parse only a subset of the features listed above, pass a list of each feature's associated
Blockclass.E.g., to only parse headings and lists:
Parser.builder().enabledBlockTypes(new HashSet<>(Arrays.asList(Heading.class, ListBlock.class)));- Parameters:
enabledBlockTypes- A list of block nodes the parser will parse. If this list is empty, the parser will not recognize any CommonMark core features.- Returns:
this
-
includeSourceSpans
public Parser.Builder includeSourceSpans(IncludeSourceSpans includeSourceSpans)
- Parameters:
includeSourceSpans- which kind of source spans should be included- Returns:
this- Since:
- 0.16.0
-
customBlockParserFactory
public Parser.Builder customBlockParserFactory(BlockParserFactory blockParserFactory)
Adds a custom block parser factory.Note that custom factories are applied before the built-in factories. This is so that extensions can change how some syntax is parsed that would otherwise be handled by built-in factories. "With great power comes great responsibility."
- Parameters:
blockParserFactory- a block parser factory implementation- Returns:
this
-
customDelimiterProcessor
public Parser.Builder customDelimiterProcessor(DelimiterProcessor delimiterProcessor)
Adds a custom delimiter processor.Note that multiple delimiter processors with the same characters can be added, as long as they have a different minimum length. In that case, the processor with the shortest matching length is used. Adding more than one delimiter processor with the same character and minimum length is invalid.
- Parameters:
delimiterProcessor- a delimiter processor implementation- Returns:
this
-
postProcessor
public Parser.Builder postProcessor(PostProcessor postProcessor)
-
inlineParserFactory
public Parser.Builder inlineParserFactory(InlineParserFactory inlineParserFactory)
Overrides the parser used for inline markdown processing.Provide an implementation of InlineParserFactory which provides a custom inline parser to modify how the following are parsed: bold (**) italic (*) strikethrough (~~) backtick quote (`) link ([title](http://)) image ()
Note that if this method is not called or the inline parser factory is set to null, then the default implementation will be used.
- Parameters:
inlineParserFactory- an inline parser factory implementation- Returns:
this
-
getInlineParserFactory
private InlineParserFactory getInlineParserFactory()
-
-