Package org.commonmark.internal
Class InlineParserImpl
- java.lang.Object
-
- org.commonmark.internal.InlineParserImpl
-
- All Implemented Interfaces:
InlineParserState,InlineParser
public class InlineParserImpl extends java.lang.Object implements InlineParser, InlineParserState
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classInlineParserImpl.DelimiterDataprivate static classInlineParserImpl.DestinationTitleA destination and optional title for a link or image.private static classInlineParserImpl.LinkInfoImpl
-
Field Summary
Fields Modifier and Type Field Description private InlineParserContextcontextprivate java.util.Map<java.lang.Character,DelimiterProcessor>delimiterProcessorsprivate booleanincludeSourceSpansprivate java.util.List<InlineContentParserFactory>inlineContentParserFactoriesprivate java.util.Map<java.lang.Character,java.util.List<InlineContentParser>>inlineParsersprivate BracketlastBracketTop opening bracket ([or![)).private DelimiterlastDelimiterTop delimiter (emphasis, strong emphasis or custom emphasis).private java.util.BitSetlinkMarkersprivate java.util.List<LinkProcessor>linkProcessorsprivate Scannerscannerprivate java.util.BitSetspecialCharactersprivate inttrailingSpaces
-
Constructor Summary
Constructors Constructor Description InlineParserImpl(InlineParserContext context)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddBracket(Bracket bracket)private static voidaddDelimiterProcessorForChar(char delimiterChar, DelimiterProcessor toAdd, java.util.Map<java.lang.Character,DelimiterProcessor> delimiterProcessors)private static voidaddDelimiterProcessors(java.lang.Iterable<DelimiterProcessor> delimiterProcessors, java.util.Map<java.lang.Character,DelimiterProcessor> map)private static java.util.Map<java.lang.Character,DelimiterProcessor>calculateDelimiterProcessors(java.util.List<DelimiterProcessor> delimiterProcessors)private java.util.List<InlineContentParserFactory>calculateInlineContentParserFactories(java.util.List<InlineContentParserFactory> customFactories)private static java.util.BitSetcalculateLinkMarkers(java.util.Set<java.lang.Character> linkMarkers)private java.util.List<LinkProcessor>calculateLinkProcessors(java.util.List<LinkProcessor> linkProcessors)private static java.util.BitSetcalculateSpecialCharacters(java.util.BitSet linkMarkers, java.util.Set<java.lang.Character> delimiterCharacters, java.util.List<InlineContentParserFactory> inlineContentParserFactories)private java.util.Map<java.lang.Character,java.util.List<InlineContentParser>>createInlineContentParsers()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 NodeparseCloseBracket()Try to match close bracket against an opening in the delimiter stack.private java.util.List<? extends Node>parseDelimiters(DelimiterProcessor delimiterProcessor, char delimiterChar)Attempt to parse delimiters like emphasis, strong emphasis or custom delimiters.private java.util.List<? extends Node>parseInline()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 NodeparseLineBreak()private static java.lang.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 java.lang.StringparseLinkLabel(Scanner scanner)Attempt to parse a link label, returning the label between the brackets or null.private java.util.List<? extends Node>parseLinkMarker()If next character is[, add a bracket to the stack.private NodeparseLinkOrImage(Bracket opener, Position beforeClose)private static java.lang.StringparseLinkTitle(Scanner scanner)Attempt to parse link title (sans quotes), returning the string or null if no match.private NodeparseOpenBracket()Add open bracket to delimiter stack and add a text node to block's children.private NodeparseText()Parse 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 voidremoveLastBracket()private 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.Scannerscanner()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 Detail
-
context
private final InlineParserContext context
-
inlineContentParserFactories
private final java.util.List<InlineContentParserFactory> inlineContentParserFactories
-
delimiterProcessors
private final java.util.Map<java.lang.Character,DelimiterProcessor> delimiterProcessors
-
linkProcessors
private final java.util.List<LinkProcessor> linkProcessors
-
specialCharacters
private final java.util.BitSet specialCharacters
-
linkMarkers
private final java.util.BitSet linkMarkers
-
inlineParsers
private java.util.Map<java.lang.Character,java.util.List<InlineContentParser>> inlineParsers
-
scanner
private Scanner scanner
-
includeSourceSpans
private boolean includeSourceSpans
-
trailingSpaces
private int trailingSpaces
-
lastDelimiter
private Delimiter lastDelimiter
Top delimiter (emphasis, strong emphasis or custom emphasis). (Brackets are on a separate stack, different from the algorithm described in the spec.)
-
lastBracket
private Bracket lastBracket
Top opening bracket ([or![)).
-
-
Constructor Detail
-
InlineParserImpl
public InlineParserImpl(InlineParserContext context)
-
-
Method Detail
-
calculateInlineContentParserFactories
private java.util.List<InlineContentParserFactory> calculateInlineContentParserFactories(java.util.List<InlineContentParserFactory> customFactories)
-
calculateLinkProcessors
private java.util.List<LinkProcessor> calculateLinkProcessors(java.util.List<LinkProcessor> linkProcessors)
-
calculateDelimiterProcessors
private static java.util.Map<java.lang.Character,DelimiterProcessor> calculateDelimiterProcessors(java.util.List<DelimiterProcessor> delimiterProcessors)
-
addDelimiterProcessors
private static void addDelimiterProcessors(java.lang.Iterable<DelimiterProcessor> delimiterProcessors, java.util.Map<java.lang.Character,DelimiterProcessor> map)
-
addDelimiterProcessorForChar
private static void addDelimiterProcessorForChar(char delimiterChar, DelimiterProcessor toAdd, java.util.Map<java.lang.Character,DelimiterProcessor> delimiterProcessors)
-
calculateLinkMarkers
private static java.util.BitSet calculateLinkMarkers(java.util.Set<java.lang.Character> linkMarkers)
-
calculateSpecialCharacters
private static java.util.BitSet calculateSpecialCharacters(java.util.BitSet linkMarkers, java.util.Set<java.lang.Character> delimiterCharacters, java.util.List<InlineContentParserFactory> inlineContentParserFactories)
-
createInlineContentParsers
private java.util.Map<java.lang.Character,java.util.List<InlineContentParser>> createInlineContentParsers()
-
scanner
public Scanner 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
public void parse(SourceLines lines, Node block)
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
void reset(SourceLines lines)
-
text
private Text text(SourceLines sourceLines)
-
parseInline
private java.util.List<? extends Node> parseInline()
Parse the next inline element in subject, advancing our position. On success, return the new inline node. On failure, return null.
-
parseDelimiters
private java.util.List<? extends Node> parseDelimiters(DelimiterProcessor delimiterProcessor, char delimiterChar)
Attempt to parse delimiters like emphasis, strong emphasis or custom delimiters.
-
parseOpenBracket
private Node parseOpenBracket()
Add open bracket to delimiter stack and add a text node to block's children.
-
parseLinkMarker
private java.util.List<? extends Node> parseLinkMarker()
If next character is[, add a bracket to the stack. Otherwise, return null.
-
parseCloseBracket
private Node 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.
-
addBracket
private void addBracket(Bracket bracket)
-
removeLastBracket
private void removeLastBracket()
-
parseInlineDestinationTitle
private static InlineParserImpl.DestinationTitle parseInlineDestinationTitle(Scanner scanner)
Try to parse the destination and an optional title for an inline link/image.
-
parseLinkDestination
private static java.lang.String parseLinkDestination(Scanner scanner)
Attempt to parse link destination, returning the string or null if no match.
-
parseLinkTitle
private static java.lang.String parseLinkTitle(Scanner scanner)
Attempt to parse link title (sans quotes), returning the string or null if no match.
-
parseLinkLabel
static java.lang.String parseLinkLabel(Scanner scanner)
Attempt to parse a link label, returning the label between the brackets or null.
-
parseLineBreak
private Node parseLineBreak()
-
parseText
private Node 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
private void processDelimiters(Delimiter stackBottom)
-
removeDelimiterAndNodes
private void removeDelimiterAndNodes(Delimiter delim)
Remove the delimiter and the corresponding text node. For used delimiters, e.g. `*` in `*foo*`.
-
removeDelimiterKeepNode
private void removeDelimiterKeepNode(Delimiter delim)
Remove the delimiter but keep the corresponding node as text. For unused delimiters such as `_` in `foo_bar`.
-
removeDelimiter
private void removeDelimiter(Delimiter delim)
-
mergeChildTextNodes
private void mergeChildTextNodes(Node node)
-
-