Skip to main content

Crate easi_publish

Crate easi_publish 

Source
Expand description

§easi-publish

Compile Typst templates with user data into PDF or HTML documents.

§Outputs are opt-in features

Two output backends live behind cargo features, so you pull only what you use:

  • pdf (default) — render_pdf and friends, plus PdfConfig.
  • html — [render_html] and friends, plus [HtmlConfig]. Equations are exported to MathML automatically.

Enable both with features = ["pdf", "html"], or take HTML only with default-features = false, features = ["html"].

§Quick start

use easi_publish::{SharedFonts, TemplateSource, DataSet, PdfConfig, render_pdf};

let fonts = SharedFonts::new();
let template = TemplateSource::FilePath("templates/invoice.typ".into());
let data = DataSet::from_json_file(
    "invoice.json",
    serde_json::json!({"invoice_number": "INV-001"}),
).unwrap();
let pdf_bytes = render_pdf(&fonts, template, data, &PdfConfig::default()).unwrap();

§Trust model

This crate is built for app-authored (trusted) templates with untrusted data. The pattern is a fixed template plus user data supplied as a DataSet (sys.inputs and/or virtual files), which is the recommended safe shape.

It is not recommended to render user-supplied templates here: there is no compile timeout or memory bound (a! template can loop or allocate without limit), and a template can read any file under its root. File reads are confined to the template’s root, package imports (@preview/...) are denied, and there is no network access. Set the template root to None (an in-memory template with no root) to deny all disk reads. Safely rendering untrusted templates requires process isolation and is currently out of scope.

Structs§

DataSet
The data handed to a template render: an optional sys.inputs dictionary plus zero or more virtual files the template can load (json("..."), csv("..."), image("..."), read("..."), …).
Diagnostic
A single Typst diagnostic with its source location preserved.
Dict
A map from string keys to values.
Hint
A hint for resolving a Diagnostic, with its own source location.
PageRanges
A list of page ranges to be exported.
PdfConfig
Configuration for PDF generation. Uses builder pattern.
PreparedTemplate
A template read and parsed once, ready to render many times via render_pdf_prepared.
Renderer
Owns the shared render state for an application and renders registered templates by key, to PDF and/or HTML.
SharedFonts
Shared font resources that can be reused across multiple compilations.
Timestamp
A timestamp with timezone information.

Enums§

Clock
Clock source for the template’s datetime.today().
PdfStandard
A PDF standard that Typst can enforce conformance with.
PublishError
Anything that can go wrong while turning a template + data into a PDF or HTML document.
Severity
Severity of a compilation/export Diagnostic.
TemplateSource
How to load the Typst template.
Timezone
A timezone.

Functions§

evict_cache
Evict Typst’s memoization-cache entries unused for the last max_age calls to this function.
render_pdf
Render a Typst template with data into PDF bytes.
render_pdf_prepared
Render an already-parsed PreparedTemplate with data into PDF bytes.
render_pdf_to_file
Render a Typst template with data and write the PDF to a file.

Type Aliases§

Result
Convenience alias for Result<T, PublishError>.