pub fn compile_document(path: &Path, exclude_imports: bool) -> Result<Count>Expand description
Compiles a Typst document and counts its words and characters.
This function loads a Typst document, compiles it using the Typst compiler, and extracts word and character counts from the rendered output.
§Arguments
path- Path to the Typst document fileexclude_imports- Iftrue, only counts content from the main file, excluding imported/included files
§Returns
A Count struct containing word and character counts, or an error if
compilation fails.
§Errors
Returns an error if:
- The file cannot be read
- The document fails to compile
- There are syntax errors in the Typst code
§Examples
use typst_count::compile_document;
use std::path::Path;
// Count all content including imports
let count = compile_document(Path::new("document.typ"), false)?;
// Count only the main file
let count = compile_document(Path::new("document.typ"), true)?;