Skip to main content

Module content

Module content 

Source
Expand description

Body-prose parsing via twig — prov’s answer to the content_format knob deferred in docs/next-steps.md, and the ingredient that makes body-link findings code-aware (DESIGN §8’s principle: a [[…]] that is really code, e.g. [[inf] * n for _ in range(m)]] inside backticks, must never be treated as a link).

twig (a sister Zig-backed project) parses Markdown/Djot into a shared AST. render_html and code_spans are direct FFI calls into it — twig’s C ABI exposes twig_document_render_html and twig_document_nodes, no subprocess involved. (code_spans used to bind a code-block-specific accessor, then a selector query per code-bearing kind; it now filters the flat node array by kind, which needs one call and reaches the detached definition subtrees a query does not — see spans_where.) twig is a required dependency, so these are always available.

Pair code_spans with crate::link::scan_wikilinks (which is what actually uses it) to keep a body-link scan from ever treating code as prose.

Enums§

ContentFormat
Which body-prose grammar a document is written in. Maps to a twig twig::Format one-to-one; kept as prov’s own type so callers can name a format without depending on twig directly, e.g. for the content_format config knob.

Functions§

code_spans
The byte ranges in body that twig parses as code (inline code spans, fenced code blocks, raw inline/block escapes) — everything a link scan should treat as opaque; see crate::link::scan_wikilinks. Spans are returned sorted by start offset, and cover code inside a footnote definition as well as code in the document body (see spans_where).
link_spans
The byte ranges in body that twig parses as inline links — the whole [text](target) construct of each link node, in source order. This is the syntax-aware, code-aware complement to prov’s lexical [[…]] scan: twig never reports a [x](y) inside a code fence, an autolink’s angle brackets, or bracket text that is not actually a link, so a body-link scan built on these spans cannot mistake prose or code for a link. The caller slices each span and parses it with crate::link::Link::parse to read the target — each span holds exactly one link, so the parse never over-reaches.
render_html
Parse body as format and render it to HTML, via twig’s FFI.
transcode
Transcode a body from the from grammar into the to grammar.