onMatch method

  1. @override
bool onMatch(
  1. InlineParser parser,
  2. Match match
)
override

Processes match, adding nodes to parser and possibly advancing parser.

Returns whether the caller should advance parser by match[0].length.

Implementation

@override
bool onMatch(InlineParser parser, Match match) {
  final runLength = match.group(0)!.length;
  final matchStart = parser.pos;
  final matchEnd = parser.pos + runLength;
  final text = Text(parser.source.substring(matchStart, matchEnd));
  if (!requiresDelimiterRun) {
    parser.pushDelimiter(SimpleDelimiter(
      node: text,
      length: runLength,
      char: parser.source.codeUnitAt(matchStart),
      canOpen: true,
      canClose: false,
      syntax: this,
      endPos: matchEnd,
    ));
    parser.addNode(text);
    return true;
  }

  final delimiterRun = DelimiterRun.tryParse(
    parser,
    matchStart,
    matchEnd,
    syntax: this,
    node: text,
    allowIntraWord: allowIntraWord,
    tags: tags ?? const [],
  );
  if (delimiterRun != null) {
    parser.pushDelimiter(delimiterRun);
    parser.addNode(text);
    return true;
  } else {
    parser.advanceBy(runLength);
    return false;
  }
}