collect static method

MarkdownDefinitions collect(
  1. String source, {
  2. MarkdownBlockRegistry? blockRegistry,
})

Every definition in source that starts a block at the top level.

Mirrors where the block parser accepts one: at the start of the document, after a blank line, or right after another definition — a definition cannot interrupt a paragraph. Fenced code, block maths, HTML comments and custom blocks are skipped, so a [x]: y inside them is not a definition. The first definition of a label wins.

Implementation

static MarkdownDefinitions collect(
  String source, {
  MarkdownBlockRegistry? blockRegistry,
}) {
  // Every definition has `]:` in it. Most replies have none, and this keeps
  // the per-token cost of asking to one scan.
  if (!_hasLabelColon(source)) {
    return empty;
  }
  final lines =
      (source.contains('\r')
              ? source.replaceAll('\r\n', '\n').replaceAll('\r', '\n')
              : source)
          .split('\n');
  return collectLines(lines, blockRegistry: blockRegistry);
}