CONSUME-AS-DATA-07: Look blocks up by anchor
What it demonstrates
Section titled “What it demonstrates”doc.byAnchor(id) and section-scoped byAnchor resolve any ^anchor to a kind-discriminated BlockView, declared or not.
Builds on: CONSUME-AS-DATA-06: Name two tables in one section
How it’s done
Section titled “How it’s done”A TypeScript program against the library API; inline comments show the resulting values and behavior.
const doc = c.read(src, { path: "README.md" });
const extra = doc.byAnchor("extra"); // doc-wide; an UNdeclared ^extra tableif (extra?.kind === "table") extra.rows[1].Option; // narrow on .kind, then read
doc.byAnchor("components")?.kind; // "table" — declared anchors resolve toodoc.body.decision.byAnchor("missing"); // undefined — scoped to one sectionSurfaces exercised
Section titled “Surfaces exercised”doc.byAnchor(id) doc-wideSectionView.byAnchor(id) scopedBlockView .kind discriminant + narrowing