From ae38be9097bbb32142ef776e77e627ac12379000 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 15 Dec 2021 11:11:57 +0100 Subject: Set Rules Episode IV: A New Fold --- src/eval/mod.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/eval/mod.rs') diff --git a/src/eval/mod.rs b/src/eval/mod.rs index d5b33280..6dcff900 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -181,11 +181,11 @@ impl Eval for MarkupNode { Self::Linebreak => Node::Linebreak, Self::Parbreak => Node::Parbreak, Self::Strong => { - ctx.styles.set(TextNode::STRONG, !ctx.styles.get(TextNode::STRONG)); + ctx.styles.toggle(TextNode::STRONG); Node::new() } Self::Emph => { - ctx.styles.set(TextNode::EMPH, !ctx.styles.get(TextNode::EMPH)); + ctx.styles.toggle(TextNode::EMPH); Node::new() } Self::Text(text) => Node::Text(text.clone()), @@ -216,7 +216,7 @@ impl Eval for MathNode { type Output = Node; fn eval(&self, _: &mut EvalContext) -> TypResult { - let text = Node::Text(self.formula.clone()).monospaced(); + let text = Node::Text(self.formula.trim().into()).monospaced(); Ok(if self.display { Node::Block(text.into_block()) } else { @@ -229,11 +229,10 @@ impl Eval for HeadingNode { type Output = Node; fn eval(&self, ctx: &mut EvalContext) -> TypResult { - // TODO(set): Relative font size. let upscale = (1.6 - 0.1 * self.level() as f64).max(0.75); let mut styles = Styles::new(); styles.set(TextNode::STRONG, true); - styles.set(TextNode::SIZE, upscale * Length::pt(11.0)); + styles.set(TextNode::SIZE, Relative::new(upscale).into()); Ok(Node::Block( self.body().eval(ctx)?.into_block().styled(styles), )) @@ -266,7 +265,7 @@ fn labelled(_: &mut EvalContext, label: EcoString, body: Node) -> TypResult