Skip to main content

Module markdown

Module markdown 

Source
Expand description

Markdown → Typst conversion, driven by pulldown-cmark.

Policy documents are arbitrary prose: they contain $, @, #, tables, and other characters that are syntactically meaningful in Typst markup. So we don’t pass markdown through as Typst — we parse it into events and emit Typst, escaping every text run. Headings become = so Typst’s native outline() builds the table of contents and PDF bookmarks; emphasis, lists, code, blockquotes, links, rules, and tables map to their Typst forms.

Block separation is explicit: every block element (heading, list, table, blockquote, code block) is preceded by a blank line so Typst never folds a list into the paragraph above it. The WISP also uses **Bold** lines as ad-hoc sub-headings; a paragraph that is nothing but one bold run is promoted to a real (level-4) heading so it gains weight and spacing instead of bleeding into the following list.

Functions§

section_slug
Stable Typst label for a section, derived from its file name: the stem, lowercased with every non-alphanumeric run collapsed to a single -, under a wisp- namespace (e.g. access-control-policy.mdwisp-access-control-policy). May collide for unusual names; section_slugs disambiguates.
section_slugs
Per-section unique Typst labels, one per entry in sections, in order. Derived from section_slug with collisions resolved by a -2, -3, … suffix so two files that normalise to the same base slug still get distinct, non-conflicting labels. Deterministic for a given ordered sections, so the anchor side (assembly) and the link side (conversion) agree.
to_typst
Convert a markdown document to Typst markup.