mirror of
https://github.com/typst/typst
synced 2025-05-13 12:36:23 +08:00
27 lines
627 B
Rust
27 lines
627 B
Rust
use crate::prelude::*;
|
|
use crate::text::TextNode;
|
|
|
|
/// A reference to a label.
|
|
#[derive(Debug, Hash)]
|
|
pub struct RefNode(pub EcoString);
|
|
|
|
#[node(Show)]
|
|
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) -> Content {
|
|
TextNode::packed(format_eco!("@{}", self.0))
|
|
}
|
|
}
|