summaryrefslogtreecommitdiff
path: root/src/library/structure/reference.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-08-30 15:00:18 +0200
committerLaurenz <laurmaedje@gmail.com>2022-09-07 11:07:17 +0200
commit0d12f2ab23177642eef2e6bb9c583cdd0c743b33 (patch)
tree03a88594081dcf360d0d880167feb1debca970e6 /src/library/structure/reference.rs
parent0cb876ebf9138c1ee3b3c87165952a73569ffb28 (diff)
[WIP] Label and reference syntax
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)))
+ }
+}