tryMatch method

  1. @override
bool tryMatch(
  1. InlineParser parser, [
  2. int? startMatchPos
])
override

Tries to match at the parser's current position.

The parser's position can be overriden with startMatchPos. Returns whether or not the pattern successfully matched.

Implementation

@override
bool tryMatch(InlineParser parser, [int? startMatchPos]) {
  if (parser.pos > 0 && parser.charAt(parser.pos - 1) == $backquote) {
    return false;
  }

  final match = pattern.matchAsPrefix(parser.source, parser.pos);
  if (match == null) {
    return false;
  }

  if (match[1] != null && htmlEntitiesMap[match.match] == null) {
    return false;
  }

  parser.writeText();
  if (onMatch(parser, match)) parser.consume(match.match.length);
  return true;
}