summaryrefslogtreecommitdiff
path: root/crates/typst-library/src/text/space.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2024-10-27 19:04:55 +0100
committerGitHub <noreply@github.com>2024-10-27 18:04:55 +0000
commitbe7cfc85d08c545abfac08098b7b33b4bd71f37e (patch)
treef4137fa2aaa57babae1f7603a9b2ed7e688f43d8 /crates/typst-library/src/text/space.rs
parentb8034a343831e8609aec2ec81eb7eeda57aa5d81 (diff)
Split out four new crates (#5302)
Diffstat (limited to 'crates/typst-library/src/text/space.rs')
-rw-r--r--crates/typst-library/src/text/space.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/crates/typst-library/src/text/space.rs b/crates/typst-library/src/text/space.rs
new file mode 100644
index 00000000..38a55482
--- /dev/null
+++ b/crates/typst-library/src/text/space.rs
@@ -0,0 +1,31 @@
+use ecow::EcoString;
+use typst_utils::singleton;
+
+use crate::foundations::{
+ elem, Content, NativeElement, Packed, PlainText, Repr, Unlabellable,
+};
+
+/// A text space.
+#[elem(Unlabellable, PlainText, Repr)]
+pub struct SpaceElem {}
+
+impl SpaceElem {
+ /// Get the globally shared space element.
+ pub fn shared() -> &'static Content {
+ singleton!(Content, SpaceElem::new().pack())
+ }
+}
+
+impl Repr for SpaceElem {
+ fn repr(&self) -> EcoString {
+ "[ ]".into()
+ }
+}
+
+impl Unlabellable for Packed<SpaceElem> {}
+
+impl PlainText for Packed<SpaceElem> {
+ fn plain_text(&self, text: &mut EcoString) {
+ text.push(' ');
+ }
+}