Class InlineParserImpl
java.lang.Object
com.vladsch.flexmark.parser.LightInlineParserImpl
com.vladsch.flexmark.parser.internal.InlineParserImpl
- All Implemented Interfaces:
ParagraphPreProcessor, InlineParser, LightInlineParser
- Direct Known Subclasses:
CommonmarkInlineParser
public class InlineParserImpl
extends LightInlineParserImpl
implements InlineParser, ParagraphPreProcessor
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class(package private) static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BitSetprotected Map<Character, CharacterNodeFactory> protected final BitSetprotected final Map<Character, DelimiterProcessor> protected List<InlineParserExtensionFactory> protected Map<Character, List<InlineParserExtension>> private BracketTop opening bracket ([or![)).protected DelimiterTop delimiter (emphasis, strong emphasis or custom emphasis).protected LinkDestinationParserprotected List<LinkRefProcessor> protected final LinkRefProcessorDataprotected final BitSetprotected ReferenceRepositoryLink references by ID, needs to be built up using parseReference before calling parse.protected BitSetFields inherited from class LightInlineParserImpl
block, currentText, document, index, input, myParsing, options -
Constructor Summary
ConstructorsConstructorDescriptionInlineParserImpl(DataHolder options, BitSet specialCharacters, BitSet delimiterCharacters, Map<Character, DelimiterProcessor> delimiterProcessors, LinkRefProcessorData linkRefProcessorsData, List<InlineParserExtensionFactory> inlineParserExtensionFactories) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddBracket(Bracket bracket) private static voidaddDelimiterProcessorForChar(char delimiterChar, DelimiterProcessor toAdd, Map<Character, DelimiterProcessor> delimiterProcessors) private static voidaddDelimiterProcessors(List<? extends DelimiterProcessor> delimiterProcessors, Map<Character, DelimiterProcessor> map) static BitSetcalculateDelimiterCharacters(DataHolder options, Set<Character> characters) static Map<Character, DelimiterProcessor> calculateDelimiterProcessors(DataHolder options, List<DelimiterProcessor> delimiterProcessors) (package private) static Map<Character, List<InlineParserExtensionFactory>> calculateInlineParserExtensions(DataHolder options, List<InlineParserExtensionFactory> extensionFactories) static LinkRefProcessorDatacalculateLinkRefProcessors(DataHolder options, List<LinkRefProcessorFactory> linkRefProcessors) static BitSetcalculateSpecialCharacters(DataHolder options, BitSet delimiterCharacters) protected Objectclone()protected static voidcollapseLinkRefChildren(Node node, Function<LinkRefDerived, Boolean> isTentative, boolean trimFirstLastChild) protected static booleancontainsLinkRefs(Node node, Boolean isTentative) protected static booleancontainsLinkRefs(BasedSequence nodeChars, Node next, Boolean isTentative) voidfinalizeDocument(@NotNull Document document) voidinitializeDocument(@NotNull Document document) matchLinkRef(Bracket opener, int startIndex, int lookAhead, int nesting) voidmergeIfNeeded(Text first, Text last) voidmergeTextNodes(@Nullable Node fromNode, @Nullable Node toNode) voidparse(@NotNull BasedSequence content, @NotNull Node block) Parse content in block into inline children, using reference map to resolve references.booleanAttempt to parse an autolink (URL or email in pointy brackets).protected booleanParse a backslash-escaped special character, adding either the escaped character, a hard line break (if the backslash is followed by a newline), or a literal backslash to the block's children.protected booleanAttempt to parse backticks, adding either a backtick code span or a literal sequence of backticks.protected booleanIf next character is [, and ! delimiter to delimiter stack and add a text node to block's children.protected booleanTry to match close bracket against an opening in the delimiter stack.parseCustom(@NotNull BasedSequence input, @NotNull Node node, @NotNull BitSet customCharacters, @NotNull Map<Character, CharacterNodeFactory> nodeFactoryMap) protected booleanparseDelimiters(DelimiterProcessor delimiterProcessor, char delimiterChar) Attempt to parse delimiters like emphasis, strong emphasis or custom delimiters.booleanAttempt to parse an entity, return Entity object if successful.booleanAttempt to parse inline HTML.protected booleanParse the next inline element in subject, advancing input index.protected booleanparseInline(boolean customOnly) Attempt to parse link destination,intAttempt to parse a link labelAttempt to parse link title (sans quotes),booleanParse a newline.protected booleanAdd open bracket to delimiter stack and add a text node to block's children.protected intparseReference(Block block, BasedSequence s) Attempt to parse a reference definition, modifying the internal reference map.protected booleanParse a run of ordinary characters, or a single character with a special meaning in markdown, as a plain string.intpreProcessBlock(Paragraph block, ParserState state) Process Paragraph Content on closing of the paragraph block to removeIndex non-text lines.private booleanvoidprocessDelimiters(Delimiter stackBottom) voidremoveDelimiter(@NotNull Delimiter delim) voidremoveDelimiterAndNode(@NotNull Delimiter delim) Remove the delimiter and the corresponding text node.voidremoveDelimiterKeepNode(@NotNull Delimiter delim) Remove the delimiter but keep the corresponding node as text.voidremoveDelimitersBetween(@NotNull Delimiter opener, @NotNull Delimiter closer) private voidprotected 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.Methods inherited from class LightInlineParserImpl
appendNode, appendSeparateText, appendText, appendText, flushTextNode, getBlock, getCurrentText, getDocument, getIndex, getInput, getOptions, getParsing, match, matcher, matchWithGroups, moveNodes, nonIndentSp, peek, peek, setBlock, setDocument, setIndex, setInput, sp, spnl, spnlUrl, toEOLMethods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface InlineParser
toEOLMethods inherited from interface LightInlineParser
appendNode, appendSeparateText, appendText, appendText, flushTextNode, getBlock, getCurrentText, getDocument, getIndex, getInput, getOptions, getParsing, match, matcher, matchWithGroups, moveNodes, nonIndentSp, peek, peek, setBlock, setDocument, setIndex, setInput, sp, spnl, spnlUrl
-
Field Details
-
originalSpecialCharacters
-
delimiterCharacters
-
delimiterProcessors
-
linkRefProcessorsData
-
linkRefProcessors
-
inlineParserExtensions
-
inlineParserExtensionFactories
-
linkDestinationParser
-
specialCharacters
-
customCharacters
-
customSpecialCharacterFactoryMap
-
customSpecialCharacterNodes
-
referenceRepository
Link references by ID, needs to be built up using parseReference before calling parse. -
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
public InlineParserImpl(DataHolder options, BitSet specialCharacters, BitSet delimiterCharacters, Map<Character, DelimiterProcessor> delimiterProcessors, LinkRefProcessorData linkRefProcessorsData, List<InlineParserExtensionFactory> inlineParserExtensionFactories)
-
-
Method Details
-
initializeDocument
- Specified by:
initializeDocumentin interfaceInlineParser
-
finalizeDocument
- Specified by:
finalizeDocumentin interfaceInlineParser
-
getLastDelimiter
- Specified by:
getLastDelimiterin interfaceInlineParser
-
getLastBracket
- Specified by:
getLastBracketin interfaceInlineParser
-
parseCustom
@Nullable public @Nullable List<Node> parseCustom(@NotNull @NotNull BasedSequence input, @NotNull @NotNull Node node, @NotNull @NotNull BitSet customCharacters, @NotNull @NotNull Map<Character, CharacterNodeFactory> nodeFactoryMap) - Specified by:
parseCustomin interfaceInlineParser
-
parse
Parse content in block into inline children, using reference map to resolve references.- Specified by:
parsein interfaceInlineParser- Parameters:
content- the content to parse as inlineblock- the node to append resulting nodes to (as children)
-
mergeTextNodes
- Specified by:
mergeTextNodesin interfaceInlineParser
-
mergeIfNeeded
- Specified by:
mergeIfNeededin interfaceInlineParser
-
preProcessBlock
Description copied from interface:ParagraphPreProcessorProcess Paragraph Content on closing of the paragraph block to removeIndex non-text lines.This is used by extensions to take leading lines from a paragraph and convert them to other blocks
by Default leading lines that define references are removed and Reference nodes are inserted before.
- Specified by:
preProcessBlockin interfaceParagraphPreProcessor- Parameters:
block- paragraph node to processstate- parser state- Returns:
- number of characters processed from the start of the block
-
parseReference
Attempt to parse a reference definition, modifying the internal reference map.- Parameters:
block- the block whose text is being parsed for referencess- sequence of the blocks characters- Returns:
- number of characters were parsed as a reference from the start of the sequence,
0if none
-
parseInline
protected boolean parseInline()Parse the next inline element in subject, advancing input index. On success, add the result to block's children and return true. On failure, return false.- Returns:
- false on failure true on success
-
parseInline
protected boolean parseInline(boolean customOnly) -
processCustomCharacters
private boolean processCustomCharacters() -
parseNewline
public boolean parseNewline()Parse a newline. If it was preceded by two spaces, append a hard line break; otherwise a soft line break.- Specified by:
parseNewlinein interfaceInlineParser- Returns:
- true
-
parseBackslash
protected boolean parseBackslash()Parse a backslash-escaped special character, adding either the escaped character, a hard line break (if the backslash is followed by a newline), or a literal backslash to the block's children.- Returns:
- true
-
parseBackticks
protected boolean parseBackticks()Attempt to parse backticks, adding either a backtick code span or a literal sequence of backticks.- Returns:
- true if matched backticks, false otherwise
-
parseDelimiters
Attempt to parse delimiters like emphasis, strong emphasis or custom delimiters.- Parameters:
delimiterProcessor- delimiter processor instancedelimiterChar- delimiter character being processed- Returns:
- true if processed characters false otherwise
-
parseOpenBracket
protected boolean parseOpenBracket()Add open bracket to delimiter stack and add a text node to block's children.- Returns:
- true
-
parseBang
protected boolean parseBang()If next character is [, and ! delimiter to delimiter stack and add a text node to block's children. Otherwise just add a text node.- Returns:
- true if processed characters false otherwise
-
addBracket
-
removeLastBracket
private void removeLastBracket() -
matchLinkRef
private InlineParserImpl.ReferenceProcessorMatch matchLinkRef(Bracket opener, int startIndex, int lookAhead, int nesting) -
parseCloseBracket
protected boolean parseCloseBracket()Try to match close bracket against an opening in the delimiter stack. Add either a link or image, or a plain [ character, to block's children. If there is a matching delimiter, removeIndex it from the delimiter stack.Also handles custom link ref processing
- Returns:
- true
-
containsLinkRefs
-
containsLinkRefs
-
collapseLinkRefChildren
protected static void collapseLinkRefChildren(Node node, Function<LinkRefDerived, Boolean> isTentative, boolean trimFirstLastChild) -
parseLinkDestination
Attempt to parse link destination,- Specified by:
parseLinkDestinationin interfaceInlineParser- Returns:
- the string or null if no match.
-
parseLinkTitle
Attempt to parse link title (sans quotes),- Specified by:
parseLinkTitlein interfaceInlineParser- Returns:
- the string or null if no match.
-
parseLinkLabel
public int parseLinkLabel()Attempt to parse a link label- Specified by:
parseLinkLabelin interfaceInlineParser- Returns:
- number of characters parsed.
-
parseAutolink
public boolean parseAutolink()Attempt to parse an autolink (URL or email in pointy brackets).- Specified by:
parseAutolinkin interfaceInlineParser- Returns:
- true if processed characters false otherwise
-
parseHtmlInline
public boolean parseHtmlInline()Attempt to parse inline HTML.- Specified by:
parseHtmlInlinein interfaceInlineParser- Returns:
- true if processed characters false otherwise
-
parseEntity
public boolean parseEntity()Attempt to parse an entity, return Entity object if successful.- Specified by:
parseEntityin interfaceInlineParser- Returns:
- true if processed characters false otherwise
-
parseString
protected boolean parseString()Parse a run of ordinary characters, or a single character with a special meaning in markdown, as a plain string.- Returns:
- true if processed characters false otherwise
-
clone
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
scanDelimiters
protected 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.- Parameters:
delimiterProcessor- delimiter processor instancedelimiterChar- delimiter character being scanned- Returns:
- information about delimiter run, or
null
-
processDelimiters
- Specified by:
processDelimitersin interfaceInlineParser
-
removeDelimitersBetween
public void removeDelimitersBetween(@NotNull @NotNull Delimiter opener, @NotNull @NotNull Delimiter closer) - Specified by:
removeDelimitersBetweenin interfaceInlineParser
-
removeDelimiterAndNode
Remove the delimiter and the corresponding text node. For used delimiters, e.g. `*` in `*foo*`.- Specified by:
removeDelimiterAndNodein interfaceInlineParser- Parameters:
delim- delimiter to remove
-
removeDelimiterKeepNode
Remove the delimiter but keep the corresponding node as text. For unused delimiters such as `_` in `foo_bar`.- Specified by:
removeDelimiterKeepNodein interfaceInlineParser- Parameters:
delim- delimiter being processed
-
removeDelimiter
- Specified by:
removeDelimiterin interfaceInlineParser
-
calculateInlineParserExtensions
static Map<Character, List<InlineParserExtensionFactory>> calculateInlineParserExtensions(DataHolder options, List<InlineParserExtensionFactory> extensionFactories) -
calculateDelimiterCharacters
-
calculateSpecialCharacters
-
calculateDelimiterProcessors
public static Map<Character, DelimiterProcessor> calculateDelimiterProcessors(DataHolder options, List<DelimiterProcessor> delimiterProcessors) -
calculateLinkRefProcessors
public static LinkRefProcessorData calculateLinkRefProcessors(DataHolder options, List<LinkRefProcessorFactory> linkRefProcessors) -
addDelimiterProcessors
private static void addDelimiterProcessors(List<? extends DelimiterProcessor> delimiterProcessors, Map<Character, DelimiterProcessor> map) -
addDelimiterProcessorForChar
private static void addDelimiterProcessorForChar(char delimiterChar, DelimiterProcessor toAdd, Map<Character, DelimiterProcessor> delimiterProcessors)
-