… todo: rewrite me.
Note: the following content is for typst.ts <v0.6.0
Creating and Using a CompileExporter
Instance
Note: The struct CompileExporter
implements trait CompileMiddleware
.
Note: The struct CompileExporter
derives trait Compiler
.
Retrieve an exporter instance that is executed on each successful compilation (more useful for incremental compilation).
let driver = CompileExporter::default()
.with_exporter(exporter)
let driver = CompileExporter::default()
.with_exporter(exporter)
See exporter.rs for usage of the exporter feature.
Glance at current available exporters:
type WithAst = reflexo_typst::AstExporter;
type WithPdf = reflexo_typst::PdfDocExporter;
type WithSvg = reflexo_typst::PureSvgExporter;
type WithSvgHtml = reflexo_typst::SvgHtmlExporter<DefaultExportFeature>;
type WithSIR = reflexo_typst::SvgModuleExporter;
type WithText = reflexo_typst::TextExporter;
type WithAst = reflexo_typst::AstExporter;
type WithPdf = reflexo_typst::PdfDocExporter;
type WithSvg = reflexo_typst::PureSvgExporter;
type WithSvgHtml = reflexo_typst::SvgHtmlExporter<DefaultExportFeature>;
type WithSIR = reflexo_typst::SvgModuleExporter;
type WithText = reflexo_typst::TextExporter;
Creating and Using a DynamicLayoutCompiler
Instance
Note: The struct DynamicLayoutCompiler
implements trait CompileMiddleware
.
Note: The struct DynamicLayoutCompiler
derives trait Compiler
.
Enable dynamic layout based on a trait Compiler
.
let driver = DynamicLayoutCompiler::new(driver, output_dir);
let driver = DynamicLayoutCompiler::new(driver, output_dir);
Creating and Using a CompileActor
Instance
Specifical for incremental compilation (Specifically, it watches files and compiles on demand) based on some universe instance.
Example: use of struct CompileActor in tool/preview.rs in tinymist
let (intr_tx, intr_rx) = mpsc::unbounded_channel();
let actor = CompileActor::new(verse,
intr_tx, intr_rx).with_watch(Some(handle.clone()));
let (intr_tx, intr_rx) = mpsc::unbounded_channel();
let actor = CompileActor::new(verse,
intr_tx, intr_rx).with_watch(Some(handle.clone()));
Example: use of intr_tx
in tool/preview.rs in tinymist
Access the service of the CompileActor
instance.
/// Updates the overlay layer of VFS (Virtual File System)
let _ = self.intr_tx.send(Interrupt::Memory(event));
/// Reads the snapshot of the current compilation
let (tx, rx) = oneshot::channel();
self.intr_tx.send(Interrupt::SnapshotRead(tx))?;
let snapshot = rx.await
/// Updates the overlay layer of VFS (Virtual File System)
let _ = self.intr_tx.send(Interrupt::Memory(event));
/// Reads the snapshot of the current compilation
let (tx, rx) = oneshot::channel();
self.intr_tx.send(Interrupt::SnapshotRead(tx))?;
let snapshot = rx.await
Adding Exporters to a CompileActor
Instance
Example fn compile_export in compile.rs in typst-ts-cli
let mut exporter: Vec<DynExporter<CompileSnapshot<_>>> = vec![];
let handle = Arc::new(CompileHandler { exporter });
let actor = CompileActor::new_with(
verse, intr_tx, intr_rx,
CompileServerOpts {
handle,
..Default::default()
},
)
.with_enable_watch(args.watch);
let mut exporter: Vec<DynExporter<CompileSnapshot<_>>> = vec![];
let handle = Arc::new(CompileHandler { exporter });
let actor = CompileActor::new_with(
verse, intr_tx, intr_rx,
CompileServerOpts {
handle,
..Default::default()
},
)
.with_enable_watch(args.watch);