renderreportv0.7.0renderreport.casoon.de

The generated Typst source

Get the .typ source the engine would compile, for snapshot tests, linting or your own post-processing.

Engine::render_typ runs every step up to compilation and returns the Typst source as a string:

let source: String = engine.render_typ(&report)?;
std::fs::write("report.typ", &source)?;

From the CLI, --typ writes the same source for a JSON request:

renderreport render report.json --typ -o report.typ

The source is self-contained apart from images and fonts: theme tokens, helpers, page setup, the functions of the components in use and one call per component, in that order (see how a report is rendered).

Uses

  • Snapshot tests. The output is deterministic for a given request and engine version: tokens are sorted and component functions are emitted in a fixed order. renderreport’s own test suite compares against fixtures/snapshots/minimal_report.typ.
  • Debugging a template. When a render fails with a Typst diagnostic, the source shows the exact call and data that caused it.
  • Lint and format pipelines, for example typstyle, before compiling with your own Typst setup.

Data as Typst literals

Component data is turned into Typst literals by to_typst_dict: null becomes none, strings become escaped string literals, arrays become arrays and objects become dictionaries.

Edit this page on GitHub · Docs for v0.7.0