summaryrefslogtreecommitdiff
path: root/src/library/structure/heading.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-04-24 14:39:53 +0200
committerLaurenz <laurmaedje@gmail.com>2022-04-24 14:53:43 +0200
commit50e4002a2a65c27f46895103c59cb775ca60d16d (patch)
treedbd43c16ae8456536c89d64d2cfff293bb6b1148 /src/library/structure/heading.rs
parent04fb8b288aa7c80607da79db7d085a4820b95a9d (diff)
Split `show` into `realize` and `finalize`
Diffstat (limited to 'src/library/structure/heading.rs')
-rw-r--r--src/library/structure/heading.rs36
1 files changed, 15 insertions, 21 deletions
diff --git a/src/library/structure/heading.rs b/src/library/structure/heading.rs
index a352cc92..a6c87912 100644
--- a/src/library/structure/heading.rs
+++ b/src/library/structure/heading.rs
@@ -63,11 +63,15 @@ impl Show for HeadingNode {
}
}
- fn show(
+ fn realize(&self, _: &mut Context, _: StyleChain) -> TypResult<Content> {
+ Ok(self.body.clone())
+ }
+
+ fn finalize(
&self,
ctx: &mut Context,
styles: StyleChain,
- realized: Option<Content>,
+ mut realized: Content,
) -> TypResult<Content> {
macro_rules! resolve {
($key:expr) => {
@@ -75,8 +79,6 @@ impl Show for HeadingNode {
};
}
- let mut body = realized.unwrap_or_else(|| self.body.clone());
-
let mut map = StyleMap::new();
map.set(TextNode::SIZE, resolve!(Self::SIZE));
@@ -96,30 +98,22 @@ impl Show for HeadingNode {
map.set(TextNode::EMPH, Toggle);
}
- let mut seq = vec![];
if resolve!(Self::UNDERLINE) {
- body = body.underlined();
- }
-
- let above = resolve!(Self::ABOVE);
- if !above.is_zero() {
- seq.push(Content::Vertical(above.resolve(styles).into()));
+ realized = realized.underlined();
}
- seq.push(body);
-
- let below = resolve!(Self::BELOW);
- if !below.is_zero() {
- seq.push(Content::Vertical(below.resolve(styles).into()));
- }
-
- let mut content = Content::sequence(seq).styled_with_map(map);
+ realized = realized.styled_with_map(map);
if resolve!(Self::BLOCK) {
- content = Content::block(content);
+ realized = Content::block(realized);
}
- Ok(content)
+ realized = realized.spaced(
+ resolve!(Self::ABOVE).resolve(styles),
+ resolve!(Self::BELOW).resolve(styles),
+ );
+
+ Ok(realized)
}
}