1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
pub mod pretty;
pub mod prop;
pub mod util;

pub use pretty::PrettyPrinter;
pub use prop::get_no_format_nodes;

pub fn pretty_print(content: &str, width: usize) -> String {
    let root = typst_syntax::parse(content);
    if root.erroneous() {
        return content.to_string();
    }
    let disabled_nodes = get_no_format_nodes(root.clone());
    let printer = PrettyPrinter::new(disabled_nodes);
    let markup = root.cast().unwrap();
    let doc = printer.convert_markup(markup);
    doc.pretty(width).to_string()
}

#[cfg(all(target_arch = "wasm32", feature = "wasm"))]
use wasm_bindgen::prelude::*;

#[cfg(all(target_arch = "wasm32", feature = "wasm"))]
#[wasm_bindgen]
pub fn pretty_print_wasm(content: &str, width: usize) -> String {
    pretty_print(content, width)
}