diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-08-30 15:00:18 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-09-07 11:07:17 +0200 |
| commit | 0d12f2ab23177642eef2e6bb9c583cdd0c743b33 (patch) | |
| tree | 03a88594081dcf360d0d880167feb1debca970e6 /src/library/structure | |
| parent | 0cb876ebf9138c1ee3b3c87165952a73569ffb28 (diff) | |
[WIP] Label and reference syntax
Diffstat (limited to 'src/library/structure')
| -rw-r--r-- | src/library/structure/mod.rs | 2 | ||||
| -rw-r--r-- | src/library/structure/reference.rs | 28 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/library/structure/mod.rs b/src/library/structure/mod.rs index a597211e..088d1e6c 100644 --- a/src/library/structure/mod.rs +++ b/src/library/structure/mod.rs @@ -3,9 +3,11 @@ mod doc; mod heading; mod list; +mod reference; mod table; pub use doc::*; pub use heading::*; pub use list::*; +pub use reference::*; pub use table::*; 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))) + } +} |
