VALIDATION-PLANES-04: Make a section optional
What it demonstrates
Section titled “What it demonstrates”optional(section(…)) lets a slot be absent without a finding while the rest of the order still holds.
Builds on: VALIDATION-PLANES-03: Constrain section order
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 { optional } from "markdown-contract";
const c = contract({ body: sections({ order: "strict" }, [ section("Summary"), optional(section("Notes")), // may be absent section("Details"),]) });// "Summary" then "Details" (no "Notes") validates cleanSurfaces exercised
Section titled “Surfaces exercised”optional() / OptionalSpec (src/core/grammar.ts)strict order with a skippable slot (src/core/structure.ts unwrap/slotsOf)