Class DocumentParser

  • All Implemented Interfaces:
    ParserState

    public class DocumentParser
    extends java.lang.Object
    implements ParserState
    • Field Detail

      • CORE_FACTORY_TYPES

        private static final java.util.Set<java.lang.Class<? extends Block>> CORE_FACTORY_TYPES
      • NODES_TO_CORE_FACTORIES

        private static final java.util.Map<java.lang.Class<? extends Block>,​BlockParserFactory> NODES_TO_CORE_FACTORIES
      • 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 java.util.List<BlockParserFactory> blockParserFactories
      • 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
      • allBlockParsers

        private final java.util.List<BlockParser> allBlockParsers
    • Method Detail

      • getDefaultBlockParserTypes

        public static java.util.Set<java.lang.Class<? extends Block>> getDefaultBlockParserTypes()
      • calculateBlockParserFactories

        public static java.util.List<BlockParserFactory> calculateBlockParserFactories​(java.util.List<BlockParserFactory> customBlockParserFactories,
                                                                                       java.util.Set<java.lang.Class<? extends Block>> enabledBlockTypes)
      • checkEnabledBlockTypes

        public static void checkEnabledBlockTypes​(java.util.Set<java.lang.Class<? extends Block>> enabledBlockTypes)
      • parse

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

        public Document parse​(java.io.Reader input)
                       throws java.io.IOException
        Throws:
        java.io.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)
      • 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)
      • isBlank

        public boolean isBlank()
        Specified by:
        isBlank in interface ParserState
        Returns:
        true if the current line is blank starting from the index
      • parseLine

        private void parseLine​(java.lang.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​(java.lang.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()
      • processInlines

        private void processInlines()
        Walk through a block & 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.
      • 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 java.lang.String prepareLine​(java.lang.String line)
        Prepares the input line replacing \0