Crate typst_count

Crate typst_count 

Source
Expand description

A library for counting words and characters in Typst documents.

This crate provides functionality to compile Typst documents and count the words and characters in the rendered output. It works by:

  1. Compiling Typst documents using the Typst compiler
  2. Traversing the compiled document’s element tree
  3. Extracting plain text from rendered elements
  4. Counting words (by whitespace) and characters

§Features

  • Count words and characters from compiled Typst documents
  • Handle imported and included files
  • Multiple output formats (human-readable, JSON, CSV)
  • CI/CD integration with limit checking

§Examples

use typst_count::compile_document;
use std::path::Path;

let path = Path::new("document.typ");
let count = compile_document(path, false).unwrap();
println!("Words: {}, Characters: {}", count.words, count.characters);

Modules§

cli
Command-line interface definitions for typst-count.
counter
Document counting logic for Typst documents.
output
Output formatting for word and character count results.
world
A minimal implementation of Typst’s World trait for document compilation.

Functions§

check_limits
Checks if word and character counts are within specified limits.
compile_document
Compiles a Typst document and counts its words and characters.
process_files
Processes multiple Typst files and returns their counts.