Navigate without a contract
read-04 · TypeScript
parse() alone projects a document into a positioned section tree — navigation helpers and verbatim table cells, no contract required.
Builds on: One contract, two doors
The artifact
Section titled “The artifact”A TypeScript program against the library API; inline comments show the resulting values and behavior.
import { parse, findSection, blocksOfKind, rawTableRows } from "markdown-contract";
// No contract: one parse projects the document into a positioned tree.const tree = parse(src);
tree.frontmatter?.data; // parsed YAML frontmatter (untyped)tree.root.sections; // top-level sections, each knowing its source linetree.mdast; // the raw mdast, if you need to drop a level
const ports = findSection(tree.root, "Ports");const [tbl] = ports ? blocksOfKind(ports, "table") : [];if (tbl) { // verbatim cells re-split from source — inline markup intact const { header, rows } = rawTableRows(tbl, src);}What it exercises
Section titled “What it exercises”parse() → DocTree projectionfindSection / blocksOfKind navigation helpersrawTableRows source-faithful cells
Continue
Section titled “Continue”- Previous: Anchors make blocks addressable
- Next: this is the last example of the group
- Group: Read markdown as typed data · All examples
- Reference: Typed model reference