diff options
Diffstat (limited to 'library/src/structure')
| -rw-r--r-- | library/src/structure/heading.rs | 18 | ||||
| -rw-r--r-- | library/src/structure/list.rs | 34 | ||||
| -rw-r--r-- | library/src/structure/reference.rs | 20 | ||||
| -rw-r--r-- | library/src/structure/table.rs | 24 |
4 files changed, 51 insertions, 45 deletions
diff --git a/library/src/structure/heading.rs b/library/src/structure/heading.rs index 62a67000..46e98c18 100644 --- a/library/src/structure/heading.rs +++ b/library/src/structure/heading.rs @@ -12,7 +12,7 @@ pub struct HeadingNode { pub body: Content, } -#[node(Show)] +#[node(Show, Finalize)] impl HeadingNode { /// The heading's font family. Just the normal text family if `auto`. #[property(referenced)] @@ -67,12 +67,6 @@ impl HeadingNode { } .pack()) } -} - -impl Show for HeadingNode { - fn unguard_parts(&self, sel: Selector) -> Content { - Self { body: self.body.unguard(sel), ..*self }.pack() - } fn field(&self, name: &str) -> Option<Value> { match name { @@ -81,11 +75,19 @@ impl Show for HeadingNode { _ => None, } } +} - fn realize(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> { +impl Show for HeadingNode { + fn unguard_parts(&self, sel: Selector) -> Content { + Self { body: self.body.unguard(sel), ..*self }.pack() + } + + fn show(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> { Ok(BlockNode(self.body.clone()).pack()) } +} +impl Finalize for HeadingNode { fn finalize( &self, world: Tracked<dyn World>, diff --git a/library/src/structure/list.rs b/library/src/structure/list.rs index a5e1380a..499207a4 100644 --- a/library/src/structure/list.rs +++ b/library/src/structure/list.rs @@ -22,7 +22,7 @@ pub type EnumNode = ListNode<ENUM>; /// A description list. pub type DescNode = ListNode<DESC>; -#[node(Show)] +#[node(Show, Finalize)] impl<const L: ListKind> ListNode<L> { /// How the list is labelled. #[property(referenced)] @@ -80,16 +80,6 @@ impl<const L: ListKind> ListNode<L> { } .pack()) } -} - -impl<const L: ListKind> Show for ListNode<L> { - fn unguard_parts(&self, sel: Selector) -> Content { - Self { - items: self.items.map(|item| item.unguard(sel)), - ..*self - } - .pack() - } fn field(&self, name: &str) -> Option<Value> { match name { @@ -101,8 +91,18 @@ impl<const L: ListKind> Show for ListNode<L> { _ => None, } } +} - fn realize( +impl<const L: ListKind> Show for ListNode<L> { + fn unguard_parts(&self, sel: Selector) -> Content { + Self { + items: self.items.map(|item| item.unguard(sel)), + ..*self + } + .pack() + } + + fn show( &self, world: Tracked<dyn World>, styles: StyleChain, @@ -140,7 +140,7 @@ impl<const L: ListKind> Show for ListNode<L> { ListItem::Enum(_, body) => body.as_ref().clone(), ListItem::Desc(item) => Content::sequence(vec![ HNode { amount: (-body_indent).into(), weak: false }.pack(), - (item.term.clone() + TextNode(':'.into()).pack()).strong(), + (item.term.clone() + TextNode::packed(':')).strong(), SpaceNode.pack(), item.body.clone(), ]), @@ -162,7 +162,9 @@ impl<const L: ListKind> Show for ListNode<L> { } .pack()) } +} +impl<const L: ListKind> Finalize for ListNode<L> { fn finalize( &self, _: Tracked<dyn World>, @@ -312,14 +314,14 @@ impl Label { ) -> SourceResult<Content> { Ok(match self { Self::Default => match kind { - LIST => TextNode('•'.into()).pack(), - ENUM => TextNode(format_eco!("{}.", number)).pack(), + LIST => TextNode::packed('•'), + ENUM => TextNode::packed(format_eco!("{}.", number)), DESC | _ => panic!("description lists don't have a label"), }, Self::Pattern(prefix, numbering, upper, suffix) => { let fmt = numbering.apply(number); let mid = if *upper { fmt.to_uppercase() } else { fmt.to_lowercase() }; - TextNode(format_eco!("{}{}{}", prefix, mid, suffix)).pack() + TextNode::packed(format_eco!("{}{}{}", prefix, mid, suffix)) } Self::Content(content) => content.clone(), Self::Func(func, span) => { diff --git a/library/src/structure/reference.rs b/library/src/structure/reference.rs index 56f8b8e3..18f4eecb 100644 --- a/library/src/structure/reference.rs +++ b/library/src/structure/reference.rs @@ -8,23 +8,23 @@ pub struct RefNode(pub EcoString); #[node(Show)] impl RefNode { fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> { - Ok(Self(args.expect("label")?).pack()) - } -} - -impl Show for RefNode { - fn unguard_parts(&self, _: Selector) -> Content { - Self(self.0.clone()).pack() + Ok(Self(args.expect("target")?).pack()) } fn field(&self, name: &str) -> Option<Value> { match name { - "label" => Some(Value::Str(self.0.clone().into())), + "target" => Some(Value::Str(self.0.clone().into())), _ => None, } } +} + +impl Show for RefNode { + fn unguard_parts(&self, _: Selector) -> Content { + Self(self.0.clone()).pack() + } - fn realize(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> { - Ok(TextNode(format_eco!("@{}", self.0)).pack()) + fn show(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> { + Ok(TextNode::packed(format_eco!("@{}", self.0))) } } diff --git a/library/src/structure/table.rs b/library/src/structure/table.rs index 722f11e6..fbf1c7c0 100644 --- a/library/src/structure/table.rs +++ b/library/src/structure/table.rs @@ -12,7 +12,7 @@ pub struct TableNode { pub cells: Vec<Content>, } -#[node(Show)] +#[node(Show, Finalize)] impl TableNode { /// How to fill the cells. #[property(referenced)] @@ -46,6 +46,15 @@ impl TableNode { } .pack()) } + + fn field(&self, name: &str) -> Option<Value> { + match name { + "cells" => Some(Value::Array( + self.cells.iter().cloned().map(Value::Content).collect(), + )), + _ => None, + } + } } impl Show for TableNode { @@ -58,16 +67,7 @@ impl Show for TableNode { .pack() } - fn field(&self, name: &str) -> Option<Value> { - match name { - "cells" => Some(Value::Array( - self.cells.iter().cloned().map(Value::Content).collect(), - )), - _ => None, - } - } - - fn realize( + fn show( &self, world: Tracked<dyn World>, styles: StyleChain, @@ -106,7 +106,9 @@ impl Show for TableNode { } .pack()) } +} +impl Finalize for TableNode { fn finalize( &self, _: Tracked<dyn World>, |
