Class DocumentParser

java.lang.Object
org.commonmark.internal.DocumentParser
All Implemented Interfaces:
ParserState

public class DocumentParser extends Object implements ParserState
  • Field Details

    • CORE_FACTORY_TYPES

      private static final Set<Class<? extends Block>> CORE_FACTORY_TYPES
    • NODES_TO_CORE_FACTORIES

      private static final Map<Class<? extends Block>,BlockParserFactory> NODES_TO_CORE_FACTORIES
    • line

      private SourceLine line
    • lineIndex

      private int lineIndex
      Line index (0-based)
    • index

      private int index
      current index (offset) in input line (0-based)
    • column

      private int column
      current column of input line (tab causes column to go to next 4-space tab stop) (0-based)
    • columnIsInTab

      private boolean columnIsInTab
      if 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

      private final List<BlockParserFactory> blockParserFactories
    • inlineParserFactory

      private final InlineParserFactory inlineParserFactory
    • inlineContentParserFactories

      private final List<InlineContentParserFactory> inlineContentParserFactories
    • delimiterProcessors

      private final List<DelimiterProcessor> delimiterProcessors
    • linkProcessors

      private final List<LinkProcessor> linkProcessors
    • linkMarkers

      private final Set<Character> linkMarkers
    • includeSourceSpans

      private final IncludeSourceSpans includeSourceSpans
    • documentBlockParser

      private final DocumentBlockParser documentBlockParser
    • definitions

      private final Definitions definitions
    • openBlockParsers

      private final List<DocumentParser.OpenBlockParser> openBlockParsers
    • allBlockParsers

      private final List<BlockParser> allBlockParsers
  • Constructor Details

  • Method Details

    • getDefaultBlockParserTypes

      public static Set<Class<? extends Block>> getDefaultBlockParserTypes()
    • calculateBlockParserFactories

      public static List<BlockParserFactory> calculateBlockParserFactories(List<BlockParserFactory> customBlockParserFactories, Set<Class<? extends Block>> enabledBlockTypes)
    • checkEnabledBlockTypes

      public static void checkEnabledBlockTypes(Set<Class<? extends Block>> enabledBlockTypes)
    • parse

      public Document parse(String input)
      The main parsing function. Returns a parsed document AST.
    • parse

      public Document parse(Reader input) throws IOException
      Throws:
      IOException
    • getLine

      public SourceLine getLine()
      Specified by:
      getLine in interface ParserState
      Returns:
      the current source line being parsed (full line)
    • getIndex

      public int getIndex()
      Specified by:
      getIndex in interface ParserState
      Returns:
      the current index within the line (0-based)
    • getNextNonSpaceIndex

      public int getNextNonSpaceIndex()
      Specified by:
      getNextNonSpaceIndex in interface ParserState
      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 the ParserState.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 interface ParserState
      Returns:
      the current column within the line (0-based)
    • getIndent

      public int getIndent()
      Specified by:
      getIndent in interface ParserState
      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 interface ParserState
      Returns:
      true if the current line is blank starting from the index
    • getActiveBlockParser

      public BlockParser getActiveBlockParser()
      Specified by:
      getActiveBlockParser in interface ParserState
      Returns:
      the deepest open block parser
    • parseLine

      private void parseLine(String ln, int inputIndex)
      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

      private void setLine(String ln, int inputIndex)
    • 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

      private BlockStartImpl findBlockStart(BlockParser blockParser)
    • processInlines

      private void processInlines()
      Walk through a block invalid input: '&' children recursively, parsing string content into inline content where appropriate.
    • addChild

      private void addChild(DocumentParser.OpenBlockParser openBlockParser)
      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

      private void activateBlockParser(DocumentParser.OpenBlockParser openBlockParser)
    • deactivateBlockParser

      private DocumentParser.OpenBlockParser deactivateBlockParser()
    • prepareActiveBlockParserForReplacement

      private Block prepareActiveBlockParserForReplacement()
    • finalizeAndProcess

      private Document finalizeAndProcess()
    • closeBlockParsers

      private void closeBlockParsers(int count)
    • finalize

      private void finalize(BlockParser blockParser)
      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

      private void addDefinitionsFrom(BlockParser blockParser)
    • prepareLine

      private static String prepareLine(String line)
      Prepares the input line replacing \0