typst_shim/
syntax_only.rs1use std::sync::atomic::{AtomicBool, Ordering};
2use typst::{
3 Document, World,
4 diag::{SourceDiagnostic, SourceResult, Warned},
5 ecow::eco_vec,
6};
7use typst_syntax::Span;
8
9pub static SYNTAX_ONLY: AtomicBool = AtomicBool::new(false);
11
12pub fn is_syntax_only() -> bool {
14 SYNTAX_ONLY.load(Ordering::Acquire)
15}
16
17pub fn compile_opt<D>(world: &dyn World) -> Warned<SourceResult<D>>
20where
21 D: Document,
22{
23 if is_syntax_only() {
24 Warned {
25 output: Err(eco_vec![SourceDiagnostic::error(
26 Span::detached(),
27 "Compilation is disabled in syntax-only mode.",
28 )]),
29 warnings: Default::default(),
30 }
31 } else {
32 typst::compile::<D>(world)
33 }
34}