tryMatch method
Attempts to close this tag by matching the current text against its end pattern.
Implementation
bool tryMatch(InlineParser parser) {
final endMatch = syntax!.endPattern.matchAsPrefix(parser.source, parser.pos);
if (endMatch == null) {
return false;
}
if (!syntax!.requiresDelimiterRun) {
// Close the tag.
close(parser, endMatch);
return true;
}
// TODO: Move this logic into TagSyntax.
final runLength = endMatch.group(0)!.length;
final openingRunLength = endPos - startPos;
final closingMatchStart = parser.pos;
final closingMatchEnd = parser.pos + runLength - 1;
final closingDelimiterRun = _DelimiterRun.tryParse(parser, closingMatchStart, closingMatchEnd);
if (closingDelimiterRun != null && closingDelimiterRun.canClose) {
// Emphasis rules #9 and #10:
final oneRunOpensAndCloses = (openingDelimiterRun!.canOpen && openingDelimiterRun!.canClose) ||
(closingDelimiterRun.canOpen && closingDelimiterRun.canClose);
if (oneRunOpensAndCloses && (openingRunLength + closingDelimiterRun.length!) % 3 == 0) {
return false;
}
// Close the tag.
close(parser, endMatch);
return true;
} else {
return false;
}
}