Expand description
Body prose → HTML, in whichever grammar the document is written in.
Three stages run in order:
preprocess_custom_syntaxrewrites Diaryx-specific syntax (highlights, spoilers, HTML embeds) into raw HTML, skipping fenced/inline code.render_bodyparses the result as the document’sContentFormatand renders it, viatwig(throughprov::render_html).- With the
syntax-highlightingfeature, [crate::syntax] colours the fenced code blocks in that HTML. Third rather than woven into stage two becauseprov::render_htmlis one string-to-string call with no node hook — and being a pass over the output is what lets it cover all three grammars, hand-written HTML bodies included, with one implementation.
§Why twig rather than a Markdown-only parser
This crate used to run comrak, which meant Diaryx could only ever publish
Markdown, and meant the publisher parsed a document with a different engine
than the editor did — the editor has always been twig, through leaf. One
engine for three grammars is the whole reason content_format can exist:
twig is already linked into every build (via prov and leaf), it
ships a wasm32-unknown-unknown package so this crate stays portable to the
Cloudflare worker, and it covers what comrak covered — tables,
strikethrough, tasklists, footnotes, autolinks, raw-HTML passthrough.
Its HTML is not byte-identical to comrak’s: tasklists come out as
<ul class="task-list"> and footnotes as role="doc-endnotes" with #fn1
anchors rather than comrak’s #fn-1. html_format_css.css styles both
spellings, so a site published before this change and one published after
render the same.
Functions§
- preprocess_
custom_ syntax - Pre-process Diaryx’s custom syntax (highlights, spoilers, HTML embeds) into
raw HTML before the body is parsed. Every stretch the document’s own parser
calls code — or raw HTML — is copied through untouched, so a fence showing
==highlight==stays a fence showing==highlight==. - render_
body - Render a document body to HTML.