Package org.commonmark.internal
Class DocumentParser
java.lang.Object
org.commonmark.internal.DocumentParser
- All Implemented Interfaces:
ParserState
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List
<BlockParser> private boolean
private final List
<BlockParserFactory> private int
current column of input line (tab causes column to go to next 4-space tab stop) (0-based)private boolean
if the current column is within a tab character (partially consumed tab)private final LinkReferenceDefinitions
private final List
<DelimiterProcessor> private final DocumentBlockParser
private final IncludeSourceSpans
private int
private int
current index (offset) in input line (0-based)private final InlineParserFactory
private SourceLine
private int
Line index (0-based)private int
private int
private static final Map
<Class<? extends Block>, BlockParserFactory> private final List
<DocumentParser.OpenBlockParser> -
Constructor Summary
ConstructorsConstructorDescriptionDocumentParser
(List<BlockParserFactory> blockParserFactories, InlineParserFactory inlineParserFactory, List<DelimiterProcessor> delimiterProcessors, IncludeSourceSpans includeSourceSpans) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
activateBlockParser
(DocumentParser.OpenBlockParser openBlockParser) private void
addChild
(DocumentParser.OpenBlockParser openBlockParser) Add block of type tag as a child of the tip.private void
addDefinitionsFrom
(ParagraphParser paragraphParser) private void
addLine()
Add line content to the active block parser.private void
private void
advance()
static List
<BlockParserFactory> calculateBlockParserFactories
(List<BlockParserFactory> customBlockParserFactories, Set<Class<? extends Block>> enabledBlockTypes) static void
checkEnabledBlockTypes
(Set<Class<? extends Block>> enabledBlockTypes) private void
closeBlockParsers
(int count) private DocumentParser.OpenBlockParser
private void
finalize
(BlockParser blockParser) Finalize a block.private Document
private BlockStartImpl
findBlockStart
(BlockParser blockParser) private void
int
The column is the position within the line after tab characters have been processed as 4-space tab stops.int
int
getIndex()
getLine()
int
boolean
isBlank()
The main parsing function.private void
Analyze a line of text and update the document appropriately.private Block
private static CharSequence
prepareLine
(CharSequence line) Prepares the input line replacing\0
private void
Walk through a block invalid input: '&' children recursively, parsing string content into inline content where appropriate.private void
setLine
(CharSequence ln) private void
setNewColumn
(int newColumn) private void
setNewIndex
(int newIndex)
-
Field Details
-
CORE_FACTORY_TYPES
-
NODES_TO_CORE_FACTORIES
-
line
-
lineIndex
private int lineIndexLine index (0-based) -
index
private int indexcurrent index (offset) in input line (0-based) -
column
private int columncurrent column of input line (tab causes column to go to next 4-space tab stop) (0-based) -
columnIsInTab
private boolean columnIsInTabif the current column is within a tab character (partially consumed tab) -
nextNonSpace
private int nextNonSpace -
nextNonSpaceColumn
private int nextNonSpaceColumn -
indent
private int indent -
blank
private boolean blank -
blockParserFactories
-
inlineParserFactory
-
delimiterProcessors
-
includeSourceSpans
-
documentBlockParser
-
definitions
-
openBlockParsers
-
allBlockParsers
-
-
Constructor Details
-
DocumentParser
public DocumentParser(List<BlockParserFactory> blockParserFactories, InlineParserFactory inlineParserFactory, List<DelimiterProcessor> delimiterProcessors, IncludeSourceSpans includeSourceSpans)
-
-
Method Details
-
getDefaultBlockParserTypes
-
calculateBlockParserFactories
public static List<BlockParserFactory> calculateBlockParserFactories(List<BlockParserFactory> customBlockParserFactories, Set<Class<? extends Block>> enabledBlockTypes) -
checkEnabledBlockTypes
-
parse
The main parsing function. Returns a parsed document AST. -
parse
- Throws:
IOException
-
getLine
- Specified by:
getLine
in interfaceParserState
- Returns:
- the current source line being parsed (full line)
-
getIndex
public int getIndex()- Specified by:
getIndex
in interfaceParserState
- Returns:
- the current index within the line (0-based)
-
getNextNonSpaceIndex
public int getNextNonSpaceIndex()- Specified by:
getNextNonSpaceIndex
in interfaceParserState
- Returns:
- the index of the next non-space character starting from
ParserState.getIndex()
(may be the same) (0-based)
-
getColumn
public int getColumn()Description copied from interface:ParserState
The column is the position within the line after tab characters have been processed as 4-space tab stops. If the line doesn't contain any tabs, it's the same as theParserState.getIndex()
. If the line starts with a tab, followed by text, then the column for the first character of the text is 4 (the index is 1).- Specified by:
getColumn
in interfaceParserState
- Returns:
- the current column within the line (0-based)
-
getIndent
public int getIndent()- Specified by:
getIndent
in interfaceParserState
- Returns:
- the indentation in columns (either by spaces or tab stop of 4), starting from
ParserState.getColumn()
-
isBlank
public boolean isBlank()- Specified by:
isBlank
in interfaceParserState
- Returns:
- true if the current line is blank starting from the index
-
getActiveBlockParser
- Specified by:
getActiveBlockParser
in interfaceParserState
- Returns:
- the deepest open block parser
-
parseLine
Analyze a line of text and update the document appropriately. We parse markdown text by calling this on each line of input, then finalizing the document. -
setLine
-
findNextNonSpace
private void findNextNonSpace() -
setNewIndex
private void setNewIndex(int newIndex) -
setNewColumn
private void setNewColumn(int newColumn) -
advance
private void advance() -
addLine
private void addLine()Add line content to the active block parser. We assume it can accept lines -- that check should be done before calling this. -
addSourceSpans
private void addSourceSpans() -
findBlockStart
-
finalize
Finalize a block. Close it and do any necessary postprocessing, e.g. setting the content of blocks and collecting link reference definitions from paragraphs. -
addDefinitionsFrom
-
processInlines
private void processInlines()Walk through a block invalid input: '&' children recursively, parsing string content into inline content where appropriate. -
addChild
Add block of type tag as a child of the tip. If the tip can't accept children, close and finalize it and try its parent, and so on until we find a block that can accept children. -
activateBlockParser
-
deactivateBlockParser
-
prepareActiveBlockParserForReplacement
-
finalizeAndProcess
-
closeBlockParsers
private void closeBlockParsers(int count) -
prepareLine
Prepares the input line replacing\0
-