parseDocument function
MdDocument
parseDocument(
- String src,
- bool useDollar, [
- MarkdownBlockRegistry? registry,
- MarkdownDefinitions? definitions,
Parses src. Link and footnote definitions are collected from src
itself unless definitions is given — the incremental view passes the
whole document's, because it parses one segment at a time.
Implementation
MdDocument parseDocument(
String src,
bool useDollar, [
MarkdownBlockRegistry? registry,
MarkdownDefinitions? definitions,
]) {
// Two full rewrites of the source, for a character most sources do not
// contain. Checking first is one scan that usually ends in none.
final normalized = src.contains('\r')
? src.replaceAll('\r\n', '\n').replaceAll('\r', '\n')
: src;
final lines = normalized.split('\n');
final defs =
definitions ??
MarkdownDefinitions.collectLines(lines, blockRegistry: registry);
return MdDocument(children: parseBlocks(lines, useDollar, registry, defs));
}