Skip to content

VALIDATION-PLANES-04: Make a section optional

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

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 clean
  • optional() / OptionalSpec (src/core/grammar.ts)
  • strict order with a skippable slot (src/core/structure.ts unwrap/slotsOf)