canEndBlock method

  1. @override
bool canEndBlock(
  1. BlockParser parser
)
override

Implementation

@override
bool canEndBlock(BlockParser parser) {
  // An empty list cannot interrupt a paragraph. See
  // https://spec.commonmark.org/0.30/#example-285.
  // Ideally, [BlockSyntax.canEndBlock] should be changed to be a method
  // which accepts a [BlockParser], but this would be a breaking change,
  // so we're going with this temporarily.
  final match = pattern.firstMatch(parser.current.content)!;

  // Allow only lists starting with 1 to interrupt paragraphs, if it is an
  // ordered list. See https://spec.commonmark.org/0.30/#example-304.
  // But there should be an exception for nested ordered lists, for example:
  // ```
  // 1. one
  // 2. two
  //   3. three
  //   4. four
  // 5. five
  // ```
  if (parser.parentSyntax is! ListSyntax &&
      match[1] != null &&
      match[1] != '1') {
    return false;
  }

  // An empty list item cannot interrupt a paragraph. See
  // https://spec.commonmark.org/0.30/#example-285
  return match[2]?.isNotEmpty ?? false;
}