diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-11-03 11:44:53 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-11-03 13:35:39 +0100 |
| commit | 37a7afddfaffd44cb9bc013c9506599267e08983 (patch) | |
| tree | 20e7d62d3c5418baff01a21d0406b91bf3096214 /library/src/structure/reference.rs | |
| parent | 56342bd972a13ffe21beaf2b87ab7eb1597704b4 (diff) | |
Split crates
Diffstat (limited to 'library/src/structure/reference.rs')
| -rw-r--r-- | library/src/structure/reference.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/library/src/structure/reference.rs b/library/src/structure/reference.rs new file mode 100644 index 00000000..632ecba5 --- /dev/null +++ b/library/src/structure/reference.rs @@ -0,0 +1,29 @@ +use crate::prelude::*; + +/// A reference to a label. +#[derive(Debug, Hash)] +pub struct RefNode(pub EcoString); + +#[node(Show)] +impl RefNode { + fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> { + Ok(Self(args.expect("label")?).pack()) + } +} + +impl Show for RefNode { + fn unguard_parts(&self, _: Selector) -> Content { + Self(self.0.clone()).pack() + } + + fn field(&self, name: &str) -> Option<Value> { + match name { + "label" => Some(Value::Str(self.0.clone().into())), + _ => None, + } + } + + fn realize(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> { + Ok(TextNode(format_eco!("@{}", self.0)).pack()) + } +} |
