Skip to main content

secunit_core/wisp/render/
mod.rs

1//! Render backends. The default `Typst` backend compiles in-binary; the
2//! `Weasyprint`/`Chromium` HTML backends are opt-in and not wired yet (see
3//! `docs/wisp-pdf-export.md` §8).
4
5use std::path::{Path, PathBuf};
6
7use anyhow::{bail, Result};
8
9use super::{doc::WispDoc, Renderer};
10
11pub mod typst;
12
13/// Everything a backend needs to produce the PDF.
14pub struct RenderRequest<'a> {
15    pub doc: &'a WispDoc,
16    /// The operator's template directory (import root for Typst partials).
17    pub template_dir: &'a Path,
18    /// The composed top-level Typst source (`main.typ`).
19    pub typst_source: &'a str,
20    /// Desired PDF output path.
21    pub output: &'a Path,
22}
23
24/// Result of a render.
25pub struct RenderResult {
26    /// Page count, if the backend reports it.
27    pub pages: Option<u32>,
28    /// True once a PDF was actually written.
29    pub wrote_pdf: bool,
30    /// Any intermediate artifact written (e.g. the `.typ` source).
31    pub intermediate: Option<PathBuf>,
32}
33
34/// Dispatch to the selected backend.
35pub fn render(renderer: Renderer, req: &RenderRequest) -> Result<RenderResult> {
36    match renderer {
37        Renderer::Typst => typst::render(req),
38        Renderer::Weasyprint | Renderer::Chromium => bail!(
39            "the `{renderer}` HTML render backend is not wired yet — use the default \
40             `typst` renderer (it needs no external toolchain)"
41        ),
42    }
43}