Skip to content

DIALECT-10: Flag a dead anchor with a docRule

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

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] });
  • docRule
  • Ctx.finding
  • extractVaultRefs + Doc.byAnchor referential integrity