Package org.commonmark.parser
Class Parser
- java.lang.Object
-
- org.commonmark.parser.Parser
-
public class Parser extends java.lang.ObjectParses 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 classParser.BuilderBuilder for configuring aParser.static interfaceParser.ParserExtensionExtension forParser.
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<BlockParserFactory>blockParserFactoriesprivate java.util.List<DelimiterProcessor>delimiterProcessorsprivate IncludeSourceSpansincludeSourceSpansprivate java.util.List<InlineContentParserFactory>inlineContentParserFactoriesprivate InlineParserFactoryinlineParserFactoryprivate java.util.Set<java.lang.Character>linkMarkersprivate java.util.List<LinkProcessor>linkProcessorsprivate java.util.List<PostProcessor>postProcessors
-
Constructor Summary
Constructors Modifier Constructor Description privateParser(Parser.Builder builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Parser.Builderbuilder()Create a new builder for configuring aParser.private DocumentParsercreateDocumentParser()Nodeparse(java.lang.String input)Parse the specified input text into a tree of nodes.NodeparseReader(java.io.Reader input)Parse the specified reader into a tree of nodes.private NodepostProcess(Node document)
-
-
-
Field Detail
-
blockParserFactories
private final java.util.List<BlockParserFactory> blockParserFactories
-
inlineContentParserFactories
private final java.util.List<InlineContentParserFactory> inlineContentParserFactories
-
delimiterProcessors
private final java.util.List<DelimiterProcessor> delimiterProcessors
-
linkProcessors
private final java.util.List<LinkProcessor> linkProcessors
-
linkMarkers
private final java.util.Set<java.lang.Character> linkMarkers
-
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); // ... }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:
java.io.IOException- when reading throws an exception
-
createDocumentParser
private DocumentParser createDocumentParser()
-
-