Skip to content

CONSUME-AS-DATA-09: Collect tolerated extra sections

Sections outside the contract (via gap()/allowUnknown) partition into doc.body.unknown as a positional SectionView[].

Builds on: CONSUME-AS-DATA-02: Read one section’s prose two ways

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

const c = contract({ body: sections({ order: "strict" }, [
section("Title"), section("Overview"), section("Status"), gap(),
])});
const doc = c.read(src, { path: "status.md" });
doc.body.status.text(); // declared section, typed key
doc.body.unknown.length; // 1 — e.g. an un-modeled "## Risks"
doc.body.unknown.map(s => s.name); // ["Risks"] — heading is the handle
  • gap()
  • sections order:"strict"
  • doc.body.unknown SectionView[] read by index/iteration/.name