parseChildLines method

  1. @override
List<Line> parseChildLines(
  1. BlockParser parser
)
override

Implementation

@override
List<Line> parseChildLines(BlockParser parser) {
  // Grab all of the lines that form the alert, stripping off the ">".
  final childLines = <Line>[];
  _lazyContinuation = false;

  while (!parser.isDone) {
    final lineContent = parser.current.content.trimLeft();
    final strippedContent = lineContent.replaceFirst(RegExp(r'^>?\s*'), '');
    final match = strippedContent.isEmpty && !lineContent.startsWith('>')
        ? null
        : _contentLineRegExp.firstMatch(strippedContent);
    if (match != null) {
      childLines.add(Line(strippedContent));
      parser.advance();
      _lazyContinuation = false;
      continue;
    }

    final lastLine = childLines.isEmpty ? Line('') : childLines.last;

    // A paragraph continuation is OK. This is content that cannot be parsed
    // as any other syntax except Paragraph, and it doesn't match the bar in
    // a Setext header.
    // Because indented code blocks cannot interrupt paragraphs, a line
    // matched CodeBlockSyntax is also paragraph continuation text.
    final otherMatched =
        parser.blockSyntaxes.firstWhere((s) => s.canParse(parser));
    if ((otherMatched is ParagraphSyntax &&
            !lastLine.isBlankLine &&
            !codeFencePattern.hasMatch(lastLine.content)) ||
        (otherMatched is CodeBlockSyntax &&
            !indentPattern.hasMatch(lastLine.content))) {
      childLines.add(parser.current);
      _lazyContinuation = true;
      parser.advance();
    } else {
      break;
    }
  }

  return childLines;
}