typst_library/text/
space.rs

1use ecow::EcoString;
2use typst_utils::singleton;
3
4use crate::foundations::{
5    Content, NativeElement, Packed, PlainText, Repr, Unlabellable, elem,
6};
7
8/// A text space.
9#[elem(Unlabellable, PlainText, Repr)]
10pub struct SpaceElem {}
11
12impl SpaceElem {
13    /// Get the globally shared space element.
14    pub fn shared() -> &'static Content {
15        singleton!(Content, SpaceElem::new().pack())
16    }
17}
18
19impl Repr for SpaceElem {
20    fn repr(&self) -> EcoString {
21        "[ ]".into()
22    }
23}
24
25impl Unlabellable for Packed<SpaceElem> {}
26
27impl PlainText for Packed<SpaceElem> {
28    fn plain_text(&self, text: &mut EcoString) {
29        text.push(' ');
30    }
31}