summaryrefslogtreecommitdiff
path: root/src/library/structure/reference.rs
blob: 0a9f4f9cee66b59446fcacc74c79532cb61d6f22 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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 Vm, args: &mut Args) -> SourceResult<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, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> {
        Ok(Content::Text(format_eco!("@{}", self.0)))
    }
}