summaryrefslogtreecommitdiff
path: root/src/library/structure/reference.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/library/structure/reference.rs')
-rw-r--r--src/library/structure/reference.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/library/structure/reference.rs b/src/library/structure/reference.rs
new file mode 100644
index 00000000..0eeb4bf5
--- /dev/null
+++ b/src/library/structure/reference.rs
@@ -0,0 +1,28 @@
+use crate::library::prelude::*;
+
+/// A reference to a label.
+#[derive(Debug, Hash)]
+pub struct RefNode(pub EcoString);
+
+#[node(showable)]
+impl RefNode {
+ fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ Ok(Content::show(Self(args.expect("label")?)))
+ }
+}
+
+impl Show for RefNode {
+ fn unguard(&self, _: Selector) -> ShowNode {
+ Self(self.0.clone()).pack()
+ }
+
+ fn encode(&self, _: StyleChain) -> Dict {
+ dict! {
+ "label" => Value::Str(self.0.clone().into()),
+ }
+ }
+
+ fn realize(&self, _: &mut Context, _: StyleChain) -> TypResult<Content> {
+ Ok(Content::Text(format_eco!("@{}", self.0)))
+ }
+}