Skip to main content

transcode

Function transcode 

Source
pub fn transcode(
    body: &str,
    from: ContentFormat,
    to: ContentFormat,
) -> Result<String>
Expand description

Transcode a body from the from grammar into the to grammar.

Two callers, one move. It is what every page prov authors rather than reads goes through — prov’s about page, the history store’s index and event bodies are written as Markdown in the Rust source, where they are legible to whoever maintains them, and converted here to whatever grammar the workspace actually uses (without which an HTML workspace ends up holding .html files whose bodies are literal # Heading Markdown: prov reads them back fine, and every other tool in the world does not). It is also the engine behind convert <file> content_format, where from is the grammar the document’s own extension declares rather than always Markdown.

A body already in the target grammar is returned untouched: twig’s serializer is idempotent here, but round-tripping would buy nothing and risks reflowing prose the author deliberately wrapped.