summaryrefslogtreecommitdiff
path: root/src/library/mod.rs
blob: 9323c4c0e4fb92146e3a6cea36cdf60dd89f7482 (plain) (blame)
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
28
29
30
31
32
33
34
//! The standard library for the _Typst_ language.

use crate::func::Scope;

mod align;
mod styles;

/// Useful imports for creating your own functions.
pub mod prelude {
    pub use crate::syntax::{SyntaxTree, FuncHeader, Expression};
    pub use crate::parsing::{parse, ParseContext, ParseResult, ParseError};
    pub use crate::layout::{layout, Layout, LayoutContext, LayoutResult, LayoutError};
    pub use crate::layout::flex::FlexLayout;
    pub use crate::layout::boxed::BoxLayout;
    pub use crate::func::Function;

    pub fn err<S: Into<String>, T>(message: S) -> ParseResult<T> {
        Err(ParseError::new(message))
    }
}

pub use align::AlignFunc;
pub use styles::{ItalicFunc, BoldFunc, MonospaceFunc};


/// Create a scope with all standard functions.
pub fn std() -> Scope {
    let mut std = Scope::new();
    std.add::<BoldFunc>("bold");
    std.add::<ItalicFunc>("italic");
    std.add::<MonospaceFunc>("mono");
    std.add::<AlignFunc>("align");
    std
}