From efd1853d069fbd1476e82d015da4d0d04cfaccc0 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 7 Nov 2022 12:21:12 +0100 Subject: Show it! - New show rule syntax - Set if syntax - Removed wrap syntax --- library/src/structure/heading.rs | 18 ++++++++++-------- library/src/structure/list.rs | 34 ++++++++++++++++++---------------- library/src/structure/reference.rs | 20 ++++++++++---------- library/src/structure/table.rs | 24 +++++++++++++----------- 4 files changed, 51 insertions(+), 45 deletions(-) (limited to 'library/src/structure') 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 { match name { @@ -81,11 +75,19 @@ impl Show for HeadingNode { _ => None, } } +} - fn realize(&self, _: Tracked, _: StyleChain) -> SourceResult { +impl Show for HeadingNode { + fn unguard_parts(&self, sel: Selector) -> Content { + Self { body: self.body.unguard(sel), ..*self }.pack() + } + + fn show(&self, _: Tracked, _: StyleChain) -> SourceResult { Ok(BlockNode(self.body.clone()).pack()) } +} +impl Finalize for HeadingNode { fn finalize( &self, world: Tracked, 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; /// A description list. pub type DescNode = ListNode; -#[node(Show)] +#[node(Show, Finalize)] impl ListNode { /// How the list is labelled. #[property(referenced)] @@ -80,16 +80,6 @@ impl ListNode { } .pack()) } -} - -impl Show for ListNode { - fn unguard_parts(&self, sel: Selector) -> Content { - Self { - items: self.items.map(|item| item.unguard(sel)), - ..*self - } - .pack() - } fn field(&self, name: &str) -> Option { match name { @@ -101,8 +91,18 @@ impl Show for ListNode { _ => None, } } +} - fn realize( +impl Show for ListNode { + fn unguard_parts(&self, sel: Selector) -> Content { + Self { + items: self.items.map(|item| item.unguard(sel)), + ..*self + } + .pack() + } + + fn show( &self, world: Tracked, styles: StyleChain, @@ -140,7 +140,7 @@ impl Show for ListNode { 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 Show for ListNode { } .pack()) } +} +impl Finalize for ListNode { fn finalize( &self, _: Tracked, @@ -312,14 +314,14 @@ impl Label { ) -> SourceResult { 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 { - 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 { 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, _: StyleChain) -> SourceResult { - Ok(TextNode(format_eco!("@{}", self.0)).pack()) + fn show(&self, _: Tracked, _: StyleChain) -> SourceResult { + 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, } -#[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 { + 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 { - match name { - "cells" => Some(Value::Array( - self.cells.iter().cloned().map(Value::Content).collect(), - )), - _ => None, - } - } - - fn realize( + fn show( &self, world: Tracked, styles: StyleChain, @@ -106,7 +106,9 @@ impl Show for TableNode { } .pack()) } +} +impl Finalize for TableNode { fn finalize( &self, _: Tracked, -- cgit v1.2.3