Package org.commonmark.parser
Class Parser
java.lang.Object
org.commonmark.parser.Parser
Parses input text to a tree of nodes.
Start with the builder() method, configure the parser and build it. Example:
Parser parser = Parser.builder().build();
Node document = parser.parse("input text");
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<BlockParserFactory> private final List<DelimiterProcessor> private final IncludeSourceSpansprivate final List<InlineContentParserFactory> private final InlineParserFactoryprivate final List<LinkProcessor> private final List<PostProcessor> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Parser.Builderbuilder()Create a new builder for configuring aParser.private DocumentParserParse the specified input text into a tree of nodes.parseReader(Reader input) Parse the specified reader into a tree of nodes.private NodepostProcess(Node document)
-
Field Details
-
blockParserFactories
-
inlineContentParserFactories
-
delimiterProcessors
-
linkProcessors
-
linkMarkers
-
inlineParserFactory
-
postProcessors
-
includeSourceSpans
-
-
Constructor Details
-
Parser
-
-
Method Details
-
builder
Create a new builder for configuring aParser.- Returns:
- a builder
-
parse
Parse the specified input text into a tree of nodes.This method is thread-safe (a new parser state is used for each invocation).
- Parameters:
input- the text to parse - must not be null- Returns:
- the root node
-
parseReader
Parse the specified reader into a tree of nodes. The caller is responsible for closing the reader.
Note that if you have a file with a byte order mark (BOM), you need to skip it before handing the reader to this library. There's existing classes that do that, e.g. seeParser parser = Parser.builder().build(); try (InputStreamReader reader = new InputStreamReader(new FileInputStream("file.md"), StandardCharsets.UTF_8)) { Node document = parser.parseReader(reader); // ... }BOMInputStreamin Commons IO.This method is thread-safe (a new parser state is used for each invocation).
- Parameters:
input- the reader to parse - must not be null- Returns:
- the root node
- Throws:
IOException- when reading throws an exception
-
createDocumentParser
-
postProcess
-