Package org.commonmark.parser
Class Parser
- java.lang.Object
-
- org.commonmark.parser.Parser
-
public class Parser extends java.lang.Object
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 Modifier and Type Class Description static class
Parser.Builder
Builder for configuring aParser
.static interface
Parser.ParserExtension
Extension forParser
.
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<BlockParserFactory>
blockParserFactories
private java.util.List<DelimiterProcessor>
delimiterProcessors
private IncludeSourceSpans
includeSourceSpans
private InlineParserFactory
inlineParserFactory
private java.util.List<PostProcessor>
postProcessors
-
Constructor Summary
Constructors Modifier Constructor Description private
Parser(Parser.Builder builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Parser.Builder
builder()
Create a new builder for configuring aParser
.private DocumentParser
createDocumentParser()
Node
parse(java.lang.String input)
Parse the specified input text into a tree of nodes.Node
parseReader(java.io.Reader input)
Parse the specified reader into a tree of nodes.private Node
postProcess(Node document)
-
-
-
Field Detail
-
blockParserFactories
private final java.util.List<BlockParserFactory> blockParserFactories
-
delimiterProcessors
private final java.util.List<DelimiterProcessor> delimiterProcessors
-
inlineParserFactory
private final InlineParserFactory inlineParserFactory
-
postProcessors
private final java.util.List<PostProcessor> postProcessors
-
includeSourceSpans
private final IncludeSourceSpans includeSourceSpans
-
-
Constructor Detail
-
Parser
private Parser(Parser.Builder builder)
-
-
Method Detail
-
builder
public static Parser.Builder builder()
Create a new builder for configuring aParser
.- Returns:
- a builder
-
parse
public Node parse(java.lang.String input)
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
public Node parseReader(java.io.Reader input) throws java.io.IOException
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:
java.io.IOException
- when reading throws an exception
-
createDocumentParser
private DocumentParser createDocumentParser()
-
-