summaryrefslogtreecommitdiff
path: root/library/src/meta/reference.rs
blob: 657e5ef7c92db703b15755024c428b36db9f07ee (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::prelude::*;
use crate::text::TextNode;

/// A reference to a label.
#[func]
#[capable(Show)]
#[derive(Debug, Hash)]
pub struct RefNode(pub EcoString);

#[node]
impl RefNode {
    fn construct(_: &Vm, args: &mut Args) -> SourceResult<Content> {
        Ok(Self(args.expect("target")?).pack())
    }

    fn field(&self, name: &str) -> Option<Value> {
        match name {
            "target" => Some(Value::Str(self.0.clone().into())),
            _ => None,
        }
    }
}

impl Show for RefNode {
    fn show(&self, _: &mut Vt, _: &Content, _: StyleChain) -> SourceResult<Content> {
        Ok(TextNode::packed(format_eco!("@{}", self.0)))
    }
}