Skip to content

VALIDATION-PLANES-01: Parse markdown into a DocTree

parse(md) returns the raw DocTree of frontmatter, sections, and positions before any contract exists.

Builds on: nothing — this is the first rung of Authoring Contracts in Code: Structure, Content, and Custom Rules.

A TypeScript program against the library API; inline comments show the resulting values and behavior.

import { parse } from "markdown-contract";
const tree = parse("---\nid: T-1\n---\n## Summary\n\nShips today.\n");
tree.frontmatter.data; // { id: "T-1" }
tree.root.sections[0].name; // "Summary"
tree.root.sections[0].pos; // { line: 4, col: 1 }
tree.root.sections[0].blocks; // [{ kind: "paragraph", text: "Ships today." }]
  • parse() -> DocTree (src/core/projection.ts)
  • DocTree.frontmatter / root / mdast
  • SectionNode.name / pos / blocks