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
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.BitSet
customCharacters
protected java.util.Map<java.lang.Character,CharacterNodeFactory>
customSpecialCharacterFactoryMap
protected java.util.ArrayList<Node>
customSpecialCharacterNodes
protected java.util.BitSet
delimiterCharacters
protected java.util.Map<java.lang.Character,DelimiterProcessor>
delimiterProcessors
protected java.util.List<InlineParserExtensionFactory>
inlineParserExtensionFactories
protected java.util.Map<java.lang.Character,java.util.List<InlineParserExtension>>
inlineParserExtensions
protected Delimiter
lastDelimiter
Top delimiter (emphasis, strong emphasis or custom emphasis).protected LinkDestinationParser
linkDestinationParser
protected java.util.List<LinkRefProcessor>
linkRefProcessors
protected LinkRefProcessorData
linkRefProcessorsData
protected java.util.BitSet
originalSpecialCharacters
protected ReferenceRepository
referenceRepository
Link references by ID, needs to be built up using parseReference before calling parse.protected java.util.BitSet
specialCharacters
-
Fields inherited from class com.vladsch.flexmark.parser.LightInlineParserImpl
block, currentText, document, index, input, myParsing, options
-
-
Constructor Summary
Constructors Constructor Description InlineParserImpl(DataHolder options, java.util.BitSet specialCharacters, java.util.BitSet delimiterCharacters, java.util.Map<java.lang.Character,DelimiterProcessor> delimiterProcessors, LinkRefProcessorData linkRefProcessorsData, java.util.List<InlineParserExtensionFactory> inlineParserExtensionFactories)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.util.BitSet
calculateDelimiterCharacters(DataHolder options, java.util.Set<java.lang.Character> characters)
static java.util.Map<java.lang.Character,DelimiterProcessor>
calculateDelimiterProcessors(DataHolder options, java.util.List<DelimiterProcessor> delimiterProcessors)
static LinkRefProcessorData
calculateLinkRefProcessors(DataHolder options, java.util.List<LinkRefProcessorFactory> linkRefProcessors)
static java.util.BitSet
calculateSpecialCharacters(DataHolder options, java.util.BitSet delimiterCharacters)
protected java.lang.Object
clone()
protected static void
collapseLinkRefChildren(Node node, java.util.function.Function<LinkRefDerived,java.lang.Boolean> isTentative, boolean trimFirstLastChild)
protected static boolean
containsLinkRefs(Node node, java.lang.Boolean isTentative)
protected static boolean
containsLinkRefs(BasedSequence nodeChars, Node next, java.lang.Boolean isTentative)
void
finalizeDocument(Document document)
Bracket
getLastBracket()
Delimiter
getLastDelimiter()
void
initializeDocument(Document document)
void
mergeIfNeeded(Text first, Text last)
void
mergeTextNodes(Node fromNode, Node toNode)
void
parse(BasedSequence content, Node block)
Parse content in block into inline children, using reference map to resolve references.boolean
parseAutolink()
Attempt to parse an autolink (URL or email in pointy brackets).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.protected boolean
parseBackticks()
Attempt to parse backticks, adding either a backtick code span or a literal sequence of backticks.protected boolean
parseBang()
If next character is [, and ! delimiter to delimiter stack and add a text node to block's children.protected boolean
parseCloseBracket()
Try to match close bracket against an opening in the delimiter stack.java.util.List<Node>
parseCustom(BasedSequence input, Node node, java.util.BitSet customCharacters, java.util.Map<java.lang.Character,CharacterNodeFactory> nodeFactoryMap)
protected boolean
parseDelimiters(DelimiterProcessor delimiterProcessor, char delimiterChar)
Attempt to parse delimiters like emphasis, strong emphasis or custom delimiters.boolean
parseEntity()
Attempt to parse an entity, return Entity object if successful.boolean
parseHtmlInline()
Attempt to parse inline HTML.protected boolean
parseInline()
Parse the next inline element in subject, advancing input index.protected boolean
parseInline(boolean customOnly)
BasedSequence
parseLinkDestination()
Attempt to parse link destination,int
parseLinkLabel()
Attempt to parse a link labelBasedSequence
parseLinkTitle()
Attempt to parse link title (sans quotes),boolean
parseNewline()
Parse a newline.protected boolean
parseOpenBracket()
Add open bracket to delimiter stack and add a text node to block's children.protected int
parseReference(Block block, BasedSequence s)
Attempt to parse a reference definition, modifying the internal reference map.protected boolean
parseString()
Parse a run of ordinary characters, or a single character with a special meaning in markdown, as a plain string.int
preProcessBlock(Paragraph block, ParserState state)
Process Paragraph Content on closing of the paragraph block to removeIndex non-text lines.void
processDelimiters(Delimiter stackBottom)
void
removeDelimiter(Delimiter delim)
void
removeDelimiterAndNode(Delimiter delim)
Remove the delimiter and the corresponding text node.void
removeDelimiterKeepNode(Delimiter delim)
Remove the delimiter but keep the corresponding node as text.void
removeDelimitersBetween(Delimiter opener, Delimiter closer)
protected com.vladsch.flexmark.parser.internal.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.-
Methods inherited from class com.vladsch.flexmark.parser.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, toEOL
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vladsch.flexmark.parser.InlineParser
toEOL
-
Methods inherited from interface com.vladsch.flexmark.parser.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 Detail
-
originalSpecialCharacters
protected final java.util.BitSet originalSpecialCharacters
-
delimiterCharacters
protected final java.util.BitSet delimiterCharacters
-
delimiterProcessors
protected final java.util.Map<java.lang.Character,DelimiterProcessor> delimiterProcessors
-
linkRefProcessorsData
protected final LinkRefProcessorData linkRefProcessorsData
-
linkRefProcessors
protected java.util.List<LinkRefProcessor> linkRefProcessors
-
inlineParserExtensions
protected java.util.Map<java.lang.Character,java.util.List<InlineParserExtension>> inlineParserExtensions
-
inlineParserExtensionFactories
protected java.util.List<InlineParserExtensionFactory> inlineParserExtensionFactories
-
linkDestinationParser
protected LinkDestinationParser linkDestinationParser
-
specialCharacters
protected java.util.BitSet specialCharacters
-
customCharacters
protected java.util.BitSet customCharacters
-
customSpecialCharacterFactoryMap
protected java.util.Map<java.lang.Character,CharacterNodeFactory> customSpecialCharacterFactoryMap
-
customSpecialCharacterNodes
protected java.util.ArrayList<Node> customSpecialCharacterNodes
-
referenceRepository
protected ReferenceRepository referenceRepository
Link references by ID, needs to be built up using parseReference before calling parse.
-
lastDelimiter
protected Delimiter lastDelimiter
Top delimiter (emphasis, strong emphasis or custom emphasis). (Brackets are on a separate stack, different from the algorithm described in the spec.)
-
-
Constructor Detail
-
InlineParserImpl
public InlineParserImpl(DataHolder options, java.util.BitSet specialCharacters, java.util.BitSet delimiterCharacters, java.util.Map<java.lang.Character,DelimiterProcessor> delimiterProcessors, LinkRefProcessorData linkRefProcessorsData, java.util.List<InlineParserExtensionFactory> inlineParserExtensionFactories)
-
-
Method Detail
-
initializeDocument
public void initializeDocument(@NotNull Document document)
- Specified by:
initializeDocument
in interfaceInlineParser
-
finalizeDocument
public void finalizeDocument(@NotNull Document document)
- Specified by:
finalizeDocument
in interfaceInlineParser
-
getLastDelimiter
public Delimiter getLastDelimiter()
- Specified by:
getLastDelimiter
in interfaceInlineParser
-
getLastBracket
public Bracket getLastBracket()
- Specified by:
getLastBracket
in interfaceInlineParser
-
parseCustom
@Nullable public java.util.List<Node> parseCustom(@NotNull BasedSequence input, @NotNull Node node, @NotNull java.util.BitSet customCharacters, @NotNull java.util.Map<java.lang.Character,CharacterNodeFactory> nodeFactoryMap)
- Specified by:
parseCustom
in interfaceInlineParser
-
parse
public void parse(@NotNull BasedSequence content, @NotNull Node block)
Parse content in block into inline children, using reference map to resolve references.- Specified by:
parse
in interfaceInlineParser
- Parameters:
content
- the content to parse as inlineblock
- the node to append resulting nodes to (as children)
-
mergeTextNodes
public void mergeTextNodes(@Nullable Node fromNode, @Nullable Node toNode)
- Specified by:
mergeTextNodes
in interfaceInlineParser
-
mergeIfNeeded
public void mergeIfNeeded(Text first, Text last)
- Specified by:
mergeIfNeeded
in interfaceInlineParser
-
preProcessBlock
public int preProcessBlock(Paragraph block, ParserState state)
Description copied from interface:ParagraphPreProcessor
Process 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:
preProcessBlock
in interfaceParagraphPreProcessor
- Parameters:
block
- paragraph node to processstate
- parser state- Returns:
- number of characters processed from the start of the block
-
parseReference
protected int parseReference(Block block, BasedSequence s)
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,
0
if 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)
-
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:
parseNewline
in 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
protected boolean parseDelimiters(DelimiterProcessor delimiterProcessor, char delimiterChar)
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
-
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
protected static boolean containsLinkRefs(Node node, java.lang.Boolean isTentative)
-
containsLinkRefs
protected static boolean containsLinkRefs(BasedSequence nodeChars, Node next, java.lang.Boolean isTentative)
-
collapseLinkRefChildren
protected static void collapseLinkRefChildren(Node node, java.util.function.Function<LinkRefDerived,java.lang.Boolean> isTentative, boolean trimFirstLastChild)
-
parseLinkDestination
public BasedSequence parseLinkDestination()
Attempt to parse link destination,- Specified by:
parseLinkDestination
in interfaceInlineParser
- Returns:
- the string or null if no match.
-
parseLinkTitle
public BasedSequence parseLinkTitle()
Attempt to parse link title (sans quotes),- Specified by:
parseLinkTitle
in interfaceInlineParser
- Returns:
- the string or null if no match.
-
parseLinkLabel
public int parseLinkLabel()
Attempt to parse a link label- Specified by:
parseLinkLabel
in interfaceInlineParser
- Returns:
- number of characters parsed.
-
parseAutolink
public boolean parseAutolink()
Attempt to parse an autolink (URL or email in pointy brackets).- Specified by:
parseAutolink
in interfaceInlineParser
- Returns:
- true if processed characters false otherwise
-
parseHtmlInline
public boolean parseHtmlInline()
Attempt to parse inline HTML.- Specified by:
parseHtmlInline
in interfaceInlineParser
- Returns:
- true if processed characters false otherwise
-
parseEntity
public boolean parseEntity()
Attempt to parse an entity, return Entity object if successful.- Specified by:
parseEntity
in 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
protected java.lang.Object clone() throws java.lang.CloneNotSupportedException
- Overrides:
clone
in classjava.lang.Object
- Throws:
java.lang.CloneNotSupportedException
-
scanDelimiters
protected com.vladsch.flexmark.parser.internal.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
public void processDelimiters(Delimiter stackBottom)
- Specified by:
processDelimiters
in interfaceInlineParser
-
removeDelimitersBetween
public void removeDelimitersBetween(@NotNull Delimiter opener, @NotNull Delimiter closer)
- Specified by:
removeDelimitersBetween
in interfaceInlineParser
-
removeDelimiterAndNode
public void removeDelimiterAndNode(@NotNull Delimiter delim)
Remove the delimiter and the corresponding text node. For used delimiters, e.g. `*` in `*foo*`.- Specified by:
removeDelimiterAndNode
in interfaceInlineParser
- Parameters:
delim
- delimiter to remove
-
removeDelimiterKeepNode
public void removeDelimiterKeepNode(@NotNull Delimiter delim)
Remove the delimiter but keep the corresponding node as text. For unused delimiters such as `_` in `foo_bar`.- Specified by:
removeDelimiterKeepNode
in interfaceInlineParser
- Parameters:
delim
- delimiter being processed
-
removeDelimiter
public void removeDelimiter(@NotNull Delimiter delim)
- Specified by:
removeDelimiter
in interfaceInlineParser
-
calculateDelimiterCharacters
public static java.util.BitSet calculateDelimiterCharacters(DataHolder options, java.util.Set<java.lang.Character> characters)
-
calculateSpecialCharacters
public static java.util.BitSet calculateSpecialCharacters(DataHolder options, java.util.BitSet delimiterCharacters)
-
calculateDelimiterProcessors
public static java.util.Map<java.lang.Character,DelimiterProcessor> calculateDelimiterProcessors(DataHolder options, java.util.List<DelimiterProcessor> delimiterProcessors)
-
calculateLinkRefProcessors
public static LinkRefProcessorData calculateLinkRefProcessors(DataHolder options, java.util.List<LinkRefProcessorFactory> linkRefProcessors)
-
-