Package org.commonmark.internal
Class InlineParserImpl
java.lang.Object
org.commonmark.internal.InlineParserImpl
- All Implemented Interfaces:
InlineParserState,InlineParser
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classprivate static classA destination and optional title for a link or image.private static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final InlineParserContextprivate final Map<Character, DelimiterProcessor> private booleanprivate final List<InlineContentParserFactory> private Map<Character, List<InlineContentParser>> private BracketTop opening bracket ([or![)).private DelimiterTop delimiter (emphasis, strong emphasis or custom emphasis).private final BitSetprivate final List<LinkProcessor> private Scannerprivate final BitSetprivate int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddBracket(Bracket bracket) private static voidaddDelimiterProcessorForChar(char delimiterChar, DelimiterProcessor toAdd, Map<Character, DelimiterProcessor> delimiterProcessors) private static voidaddDelimiterProcessors(Iterable<DelimiterProcessor> delimiterProcessors, Map<Character, DelimiterProcessor> map) private static Map<Character, DelimiterProcessor> calculateDelimiterProcessors(List<DelimiterProcessor> delimiterProcessors) private List<InlineContentParserFactory> calculateInlineContentParserFactories(List<InlineContentParserFactory> customFactories) private static BitSetcalculateLinkMarkers(Set<Character> linkMarkers) private List<LinkProcessor> calculateLinkProcessors(List<LinkProcessor> linkProcessors) private static BitSetcalculateSpecialCharacters(BitSet linkMarkers, Set<Character> delimiterCharacters, List<InlineContentParserFactory> inlineContentParserFactories) private Map<Character, List<InlineContentParser>> private voidmergeChildTextNodes(Node node) private voidmergeIfNeeded(Text first, Text last, int textLength) private voidmergeTextNodesInclusive(Node fromNode, Node toNode) voidparse(SourceLines lines, Node block) Parse content in block into inline children, appending them to the block node.private NodeTry to match close bracket against an opening in the delimiter stack.parseDelimiters(DelimiterProcessor delimiterProcessor, char delimiterChar) Attempt to parse delimiters like emphasis, strong emphasis or custom delimiters.Parse the next inline element in subject, advancing our position.private static InlineParserImpl.DestinationTitleparseInlineDestinationTitle(Scanner scanner) Try to parse the destination and an optional title for an inline link/image.private Nodeprivate static StringparseLinkDestination(Scanner scanner) Attempt to parse link destination, returning the string or null if no match.private LinkInfoparseLinkInfo(Bracket opener, Position beforeClose) (package private) static StringparseLinkLabel(Scanner scanner) Attempt to parse a link label, returning the label between the brackets or null.If next character is[, add a bracket to the stack.private NodeparseLinkOrImage(Bracket opener, Position beforeClose) private static StringparseLinkTitle(Scanner scanner) Attempt to parse link title (sans quotes), returning the string or null if no match.private NodeAdd open bracket to delimiter stack and add a text node to block's children.private NodeParse the next character as plain text, and possibly more if the following characters are non-special.private voidprocessDelimiters(Delimiter stackBottom) private voidremoveDelimiter(Delimiter delim) private voidremoveDelimiterAndNodes(Delimiter delim) Remove the delimiter and the corresponding text node.private voidremoveDelimiterKeepNode(Delimiter delim) Remove the delimiter but keep the corresponding node as text.private voidremoveDelimitersBetween(Delimiter opener, Delimiter closer) private voidprivate NodereplaceBracket(Bracket opener, Node node, boolean includeMarker) (package private) voidreset(SourceLines lines) private InlineParserImpl.DelimiterDatascanDelimiters(DelimiterProcessor delimiterProcessor, char delimiterChar) Scan a sequence of characters with code delimiterChar, and return information about the number of delimiters and whether they are positioned such that they can open and/or close emphasis or strong emphasis.scanner()Return a scanner for the input for the current position (on the trigger character that the inline parser was added for).private Texttext(SourceLines sourceLines) private NodewrapBracket(Bracket opener, Node wrapperNode, boolean includeMarker)
-
Field Details
-
context
-
inlineContentParserFactories
-
delimiterProcessors
-
linkProcessors
-
specialCharacters
-
linkMarkers
-
inlineParsers
-
scanner
-
includeSourceSpans
private boolean includeSourceSpans -
trailingSpaces
private int trailingSpaces -
lastDelimiter
Top delimiter (emphasis, strong emphasis or custom emphasis). (Brackets are on a separate stack, different from the algorithm described in the spec.) -
lastBracket
Top opening bracket ([or![)).
-
-
Constructor Details
-
InlineParserImpl
-
-
Method Details
-
calculateInlineContentParserFactories
private List<InlineContentParserFactory> calculateInlineContentParserFactories(List<InlineContentParserFactory> customFactories) -
calculateLinkProcessors
-
calculateDelimiterProcessors
private static Map<Character,DelimiterProcessor> calculateDelimiterProcessors(List<DelimiterProcessor> delimiterProcessors) -
addDelimiterProcessors
private static void addDelimiterProcessors(Iterable<DelimiterProcessor> delimiterProcessors, Map<Character, DelimiterProcessor> map) -
addDelimiterProcessorForChar
private static void addDelimiterProcessorForChar(char delimiterChar, DelimiterProcessor toAdd, Map<Character, DelimiterProcessor> delimiterProcessors) -
calculateLinkMarkers
-
calculateSpecialCharacters
-
createInlineContentParsers
-
scanner
Description copied from interface:InlineParserStateReturn a scanner for the input for the current position (on the trigger character that the inline parser was added for).Note that this always returns the same instance, if you want to backtrack you need to use
Scanner.position()andScanner.setPosition(Position).- Specified by:
scannerin interfaceInlineParserState
-
parse
Parse content in block into inline children, appending them to the block node.- Specified by:
parsein interfaceInlineParser- Parameters:
lines- the source content to parse as inlineblock- the node to append resulting nodes to (as children)
-
reset
-
text
-
parseInline
Parse the next inline element in subject, advancing our position. On success, return the new inline node. On failure, return null. -
parseDelimiters
private List<? extends Node> parseDelimiters(DelimiterProcessor delimiterProcessor, char delimiterChar) Attempt to parse delimiters like emphasis, strong emphasis or custom delimiters. -
parseOpenBracket
Add open bracket to delimiter stack and add a text node to block's children. -
parseLinkMarker
If next character is[, add a bracket to the stack. Otherwise, return null. -
parseCloseBracket
Try to match close bracket against an opening in the delimiter stack. Return either a link or image, or a plain [ character. If there is a matching delimiter, remove it from the delimiter stack. -
parseLinkOrImage
-
parseLinkInfo
-
wrapBracket
-
replaceBracket
-
addBracket
-
removeLastBracket
private void removeLastBracket() -
parseInlineDestinationTitle
Try to parse the destination and an optional title for an inline link/image. -
parseLinkDestination
Attempt to parse link destination, returning the string or null if no match. -
parseLinkTitle
Attempt to parse link title (sans quotes), returning the string or null if no match. -
parseLinkLabel
Attempt to parse a link label, returning the label between the brackets or null. -
parseLineBreak
-
parseText
Parse the next character as plain text, and possibly more if the following characters are non-special. -
scanDelimiters
private InlineParserImpl.DelimiterData scanDelimiters(DelimiterProcessor delimiterProcessor, char delimiterChar) Scan a sequence of characters with code delimiterChar, and return information about the number of delimiters and whether they are positioned such that they can open and/or close emphasis or strong emphasis.- Returns:
- information about delimiter run, or
null
-
processDelimiters
-
removeDelimitersBetween
-
removeDelimiterAndNodes
Remove the delimiter and the corresponding text node. For used delimiters, e.g. `*` in `*foo*`. -
removeDelimiterKeepNode
Remove the delimiter but keep the corresponding node as text. For unused delimiters such as `_` in `foo_bar`. -
removeDelimiter
-
mergeChildTextNodes
-
mergeTextNodesInclusive
-
mergeIfNeeded
-