
Check a theme's dictionary structure against onepagr's real contract
Source:R/themes.R
check_theme.RdValidates a theme .typ file's theme and theme-grad exports by
actually evaluating them with Typst (typst eval, via Quarto's bundled
binary) rather than a hand-rolled text parser, so a theme flagged
here is confirmed to fail (or nearly fail) the exact same way it would
at real render time, not just suspected to. Checks:
Arguments
- theme
Character. A built-in theme name (e.g. "uk") or a path to a custom theme
.typfile. Default"default".- theme_path
Character or
NULL. Explicit path override, same asresolve_theme().
Value
Invisibly, a list: ok (logical), path (the resolved theme
file), error (character or NULL; set only when the file failed to
evaluate at all, in which case every field below is empty/NA),
missing / missing_grad (character vectors of required keys not
found in theme / theme-grad), type_mismatches /
type_mismatches_grad (data frames with key, expected, actual
columns), radius_card_missing / radius_card_type_mismatches (same
shape, for the nested radius-card dictionary), and unknown
(character vector of keys present in theme but outside onepagr's
known schema, informational only, not a failure; could be a typo,
or a key your own templates read directly).
Details
The file evaluates at all (catches a Typst syntax error, a missing
theme/theme-gradexport, or any other error Typst itself would raise).Every key onepagr's shipped templates and
components.typactually dereference is present, in boththemeandtheme-grad.Each present key's real Typst-evaluated type matches what onepagr expects (e.g. a color key set to a bare string, or a length key set to a color), exactly the kind of mistake that would otherwise surface as a much less legible Typst error deep inside
components.typ, pointing at the component's own code rather than the theme file that actually caused it.
Does not check color contrast or WCAG compliance: a value can be
a perfectly well-formed color and still fail WCAG (or vice versa,
though a malformed value can never pass it). That's a semantic
judgment, not a structural one, and belongs in a separate
contrast-checking function, not folded in here.
Callable standalone while developing a new theme (before ever calling
render_onepager()), or from another onepagr function or your own test
suite that wants to validate a theme up front; nothing about it is
tied to a particular call site.