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 markerLength = match[1]!.length;
  final contentLength = match.match.length - markerLength * 2;
  final contentStart = parser.pos + markerLength;
  final contentEnd = contentStart + contentLength;

  var code = parser.source.substring(contentStart, contentEnd);
  if (_shouldStrip(code)) {
    code = code.substring(1, code.length - 1);
  }
  code = code.replaceAll('\n', ' ');

  if (parser.encodeHtml) {
    code = escapeHtml(code, escapeApos: false);
  }

  parser.addNode(Element.text('code', code));
  return true;
}