Interface DelimiterProcessor

All Known Implementing Classes:
AngleQuoteDelimiterProcessor, AsteriskDelimiterProcessor, DoubleQuoteDelimiterProcessor, EmojiDelimiterProcessor, EmphasisDelimiterProcessor, InsDelimiterProcessor, QuoteDelimiterProcessorBase, SingleQuoteDelimiterProcessor, StrikethroughDelimiterProcessor, StrikethroughSubscriptDelimiterProcessor, SubscriptDelimiterProcessor, SuperscriptDelimiterProcessor, UnderscoreDelimiterProcessor, ZzzzzzDelimiterProcessor

public interface DelimiterProcessor
Custom delimiter processor for additional delimiters besides _ and *.

Note that implementations of this need to be thread-safe, the same instance may be used by multiple parsers.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    canBeCloser(String before, String after, boolean leftFlanking, boolean rightFlanking, boolean beforeIsPunctuation, boolean afterIsPunctuation, boolean beforeIsWhitespace, boolean afterIsWhiteSpace)
    Decide whether this delimiter can be a close delimiter
    boolean
    canBeOpener(String before, String after, boolean leftFlanking, boolean rightFlanking, boolean beforeIsPunctuation, boolean afterIsPunctuation, boolean beforeIsWhitespace, boolean afterIsWhiteSpace)
    Decide whether this delimiter can be an open delimiter
    char
     
    int
    Determine how many (if any) of the delimiter characters should be used.
    int
     
    char
     
    void
    process(Delimiter opener, Delimiter closer, int delimitersUsed)
    Process the matched delimiters, e.g.
    boolean
    Whether to skip delimiters that cannot be openers or closers
    Allow delimiter processor to substitute unmatched delimiters by custom nodes
  • Method Details

    • getOpeningCharacter

      char getOpeningCharacter()
      Returns:
      the character that marks the beginning of a delimited node, must not clash with any built-in special characters
    • getClosingCharacter

      char getClosingCharacter()
      Returns:
      the character that marks the the ending of a delimited node, must not clash with any built-in special characters. Note that for a symmetric delimiter such as "*", this is the same as the opening.
    • getMinLength

      int getMinLength()
      Returns:
      Minimum number of delimiter characters that are needed to activate this. Must be at least 1.
    • getDelimiterUse

      int getDelimiterUse(DelimiterRun opener, DelimiterRun closer)
      Determine how many (if any) of the delimiter characters should be used.

      This allows implementations to decide how many characters to use based on the properties of the delimiter runs. An implementation can also return 0 when it doesn't want to allow this particular combination of delimiter runs.

      Parameters:
      opener - the opening delimiter run
      closer - the closing delimiter run
      Returns:
      how many delimiters should be used; must not be greater than length of either opener or closer
    • process

      void process(Delimiter opener, Delimiter closer, int delimitersUsed)
      Process the matched delimiters, e.g. by wrapping the nodes between opener and closer in a new node, or appending a new node after the opener.

      Note that removal of the delimiter from the delimiter nodes and unlinking them is done by the caller.

      Parameters:
      opener - the delimiter with text node that contained the opening delimiter
      closer - the delimiter with text node that contained the closing delimiter
      delimitersUsed - the number of delimiters that were used
    • unmatchedDelimiterNode

      Node unmatchedDelimiterNode(InlineParser inlineParser, DelimiterRun delimiter)
      Allow delimiter processor to substitute unmatched delimiters by custom nodes
      Parameters:
      inlineParser - inline parser instance
      delimiter - delimiter run that was not matched
      Returns:
      node to replace unmatched delimiter, null or delimiter.getNode() to replace with delimiter text
    • canBeOpener

      boolean canBeOpener(String before, String after, boolean leftFlanking, boolean rightFlanking, boolean beforeIsPunctuation, boolean afterIsPunctuation, boolean beforeIsWhitespace, boolean afterIsWhiteSpace)
      Decide whether this delimiter can be an open delimiter
      Parameters:
      before - string before delimiter or '\n' if none
      after - string after delimiter or '\n' if none
      leftFlanking - is left flanking delimiter
      rightFlanking - is right flanking delimiter
      beforeIsPunctuation - is punctuation before
      afterIsPunctuation - is punctuation after
      beforeIsWhitespace - is whitespace before
      afterIsWhiteSpace - is whitespace after
      Returns:
      true if can be open delimiter
    • canBeCloser

      boolean canBeCloser(String before, String after, boolean leftFlanking, boolean rightFlanking, boolean beforeIsPunctuation, boolean afterIsPunctuation, boolean beforeIsWhitespace, boolean afterIsWhiteSpace)
      Decide whether this delimiter can be a close delimiter
      Parameters:
      before - string before delimiter or '\n' if none
      after - string after delimiter or '\n' if none
      leftFlanking - is left flanking delimiter
      rightFlanking - is right flanking delimiter
      beforeIsPunctuation - is punctuation before
      afterIsPunctuation - is punctuation after
      beforeIsWhitespace - is whitespace before
      afterIsWhiteSpace - is whitespace after
      Returns:
      true if can be open delimiter
    • skipNonOpenerCloser

      boolean skipNonOpenerCloser()
      Whether to skip delimiters that cannot be openers or closers
      Returns:
      true if to skip