parse method

  1. @override
Node parse(
  1. BlockParser parser
)
override

Implementation

@override
Node parse(BlockParser parser) {
  final openingFence = _FenceMatch.fromMatch(pattern.firstMatch(
    escapePunctuation(parser.current.content),
  )!);

  var text = parseChildLines(
    parser,
    openingFence.marker,
    openingFence.indent,
  ).map((e) => e.content).join('\n');

  if (parser.document.encodeHtml) {
    text = escapeHtml(text, escapeApos: false);
  }
  if (text.isNotEmpty) {
    text = '$text\n';
  }

  final code = Element.text('code', text);
  if (openingFence.hasLanguage) {
    var language = decodeHtmlCharacters(openingFence.language);
    if (parser.document.encodeHtml) {
      language = escapeHtmlAttribute(language);
    }
    code.attributes['class'] = getLanguageClass(language);
  }

  return Element('pre', [code]);
}