summaryrefslogtreecommitdiff
path: root/crates/typst-library/src/meta/mod.rs
blob: 1019864f0c0297971d32bd08e0a4c4351bca812d (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! Interaction between document parts.

mod bibliography;
mod cite;
mod context;
mod counter;
mod document;
mod figure;
mod footnote;
mod heading;
mod link;
mod metadata;
#[path = "numbering.rs"]
mod numbering_;
mod outline;
#[path = "query.rs"]
mod query_;
mod reference;
mod state;

pub use self::bibliography::*;
pub use self::cite::*;
pub use self::context::*;
pub use self::counter::*;
pub use self::document::*;
pub use self::figure::*;
pub use self::footnote::*;
pub use self::heading::*;
pub use self::link::*;
pub use self::metadata::*;
pub use self::numbering_::*;
pub use self::outline::*;
pub use self::query_::*;
pub use self::reference::*;
pub use self::state::*;

use crate::prelude::*;
use crate::text::TextElem;

/// Hook up all meta definitions.
pub(super) fn define(global: &mut Scope) {
    global.category("meta");
    global.define_type::<Label>();
    global.define_type::<Selector>();
    global.define_type::<Location>();
    global.define_type::<Counter>();
    global.define_type::<State>();
    global.define_elem::<DocumentElem>();
    global.define_elem::<RefElem>();
    global.define_elem::<LinkElem>();
    global.define_elem::<OutlineElem>();
    global.define_elem::<HeadingElem>();
    global.define_elem::<FigureElem>();
    global.define_elem::<FootnoteElem>();
    global.define_elem::<CiteElem>();
    global.define_elem::<BibliographyElem>();
    global.define_elem::<MetadataElem>();
    global.define_func::<locate>();
    global.define_func::<style>();
    global.define_func::<layout>();
    global.define_func::<numbering>();
    global.define_func::<query>();
}

/// The named with which an element is referenced.
pub trait LocalName {
    /// Get the name in the given language and (optionally) region.
    fn local_name(&self, lang: Lang, region: Option<Region>) -> &'static str;

    /// Resolve the local name with a style chain.
    fn local_name_in(&self, styles: StyleChain) -> &'static str {
        self.local_name(TextElem::lang_in(styles), TextElem::region_in(styles))
    }
}