DIALECT-10: Flag a dead anchor with a docRule
What it demonstrates
Section titled “What it demonstrates”A docRule pairs extractVaultRefs with byAnchor to flag a #^anchor fragment that resolves nowhere in the same doc.
Builds on: DIALECT-09: Require an anchor with a contract
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.
import { contract, docRule, sections, section, extractVaultRefs } from "markdown-contract";
const deadAnchor = docRule("dialect/dead-anchor", (doc, ctx) => extractVaultRefs(doc.body.section("Notes").text("all")) .filter(r => r.fragment?.startsWith("^") && !doc.byAnchor(r.fragment.slice(1))) .map(r => ctx.finding({ id: "dialect/dead-anchor", message: `no block ${r.fragment}` })));
const c = contract({ body: sections({}, [section("Notes", {})]), rules: [deadAnchor] });Surfaces exercised
Section titled “Surfaces exercised”docRuleCtx.findingextractVaultRefs + Doc.byAnchor referential integrity