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§
- Content
Format - Which body-prose grammar a document is written in. Maps to a
twigtwig::Formatone-to-one; kept as prov’s own type so callers can name a format without depending ontwigdirectly, e.g. for thecontent_formatconfig knob.
Functions§
- code_
spans - The byte ranges in
bodythattwigparses as code (inline code spans, fenced code blocks, raw inline/block escapes) — everything a link scan should treat as opaque; seecrate::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 (seespans_where). - link_
spans - The byte ranges in
bodythattwigparses as inline links — the whole[text](target)construct of eachlinknode, 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 withcrate::link::Link::parseto read the target — each span holds exactly one link, so the parse never over-reaches. - render_
html - Parse
bodyasformatand render it to HTML, viatwig’s FFI. - transcode
- Transcode a body from the
fromgrammar into thetogrammar.