parse method
Parses source.
A YAML mapping fenced by --- at the beginning of the source becomes
MdcDocument.frontmatter. Raw HTML remains text and is never interpreted
by the parser.
Implementation
MdcDocument parse(String source) {
final (:body, :frontmatter) = _readFrontmatter(source);
final nodes = parseMdcBody(body);
late MdcDocument document;
try {
document = MdcDocument(nodes: nodes, frontmatter: frontmatter);
} on ArgumentError catch (error) {
throw FormatException('Invalid MDC frontmatter: ${error.message}');
} on TypeError {
throw const FormatException('MDC frontmatter keys must be strings.');
}
for (final transform in transforms) {
document = transform(document);
}
return headingIds ? document.withHeadingIds() : document;
}