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 IncludeSourceSpans
private final InlineParserFactory
private final List
<PostProcessor> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Parser.Builder
builder()
Create a new builder for configuring aParser
.private DocumentParser
Parse the specified input text into a tree of nodes.parseReader
(Reader input) Parse the specified reader into a tree of nodes.private Node
postProcess
(Node document)
-
Field Details
-
blockParserFactories
-
delimiterProcessors
-
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); // ... }
BOMInputStream
in 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
-