Skip to content

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

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 line
tree.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);
}
  • parse() → DocTree projection
  • findSection / blocksOfKind navigation helpers
  • rawTableRows source-faithful cells