Skip to content

Tables as typed rows

read-02 · TypeScript

A table leaf with cell schemas reads back as an iterable of typed rows — no cell parsing in the consumer.

Builds on: One contract, two doors

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

import { contract, sections, section, table } from "markdown-contract";
import { z } from "zod";
const runbook = contract({
body: sections({ order: "none", allowUnknown: true }, [
section("Ports", {
content: table({
columns: ["Name", "Port"],
minRows: 1,
cells: { Port: z.coerce.number().int() },
}),
}),
]),
});
const doc = runbook.read(src, { path: "runbooks/api.md" });
// The section's sole content is a table, so its key IS the table view.
const ports = doc.body.Ports;
for (const row of ports) {
row.Name; // string — raw cell text
row.Port; // number — the cells schema typed it
}
ports.column("Name"); // one column, across all rows
ports.find((r) => r.Port === 8080); // the first matching row
ports.rowPos(0); // source position of the first data row
  • table leaf with cell schemas
  • TableView iteration, column(), find()
  • table promotion (the heading is the table)
  • row positions for follow-up findings