Skip to content

VALIDATION-PLANES-09: Require a fenced code block in a language

code({lang}) requires a fenced block and pins its language, separating the structural kind-gate from the content check.

Builds on: VALIDATION-PLANES-07: Require a block kind: a table

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

import { code } from "markdown-contract";
const c = contract({ body: sections({}, [
section("Example", { content: code({ lang: "ts" }) }),
]) });
// no fenced block -> structure/block-missing
// a ```js block where ```ts is required -> content/code/lang
  • code() leaf, lang pin (src/core/leaves.ts)
  • structure kind-gate (block-missing) vs content/code/lang split (src/core/structure.ts + content.ts)