diff options
Diffstat (limited to 'src/library')
| -rw-r--r-- | src/library/layout.rs | 25 | ||||
| -rw-r--r-- | src/library/text.rs | 22 |
2 files changed, 17 insertions, 30 deletions
diff --git a/src/library/layout.rs b/src/library/layout.rs index 08924bad..4903077b 100644 --- a/src/library/layout.rs +++ b/src/library/layout.rs @@ -20,7 +20,7 @@ pub fn page(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { let right = args.named(ctx, "right"); let bottom = args.named(ctx, "bottom"); let flip = args.named(ctx, "flip"); - let body = args.eat::<TemplateValue>(ctx); + let body = args.expect::<TemplateValue>(ctx, "body").unwrap_or_default(); Value::template(move |ctx| { let snapshot = ctx.state.clone(); @@ -66,13 +66,10 @@ pub fn page(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { } ctx.pagebreak(false, true, span); + body.exec(ctx); - if let Some(body) = &body { - // TODO: Restrict body to a single page? - body.exec(ctx); - ctx.state = snapshot; - ctx.pagebreak(true, false, span); - } + ctx.state = snapshot; + ctx.pagebreak(true, false, span); }) } @@ -111,7 +108,7 @@ pub fn align(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { let second = args.eat::<AlignValue>(ctx); let mut horizontal = args.named::<AlignValue>(ctx, "horizontal"); let mut vertical = args.named::<AlignValue>(ctx, "vertical"); - let body = args.eat::<TemplateValue>(ctx); + let body = args.expect::<TemplateValue>(ctx, "body").unwrap_or_default(); for value in first.into_iter().chain(second) { match value.axis() { @@ -126,23 +123,19 @@ pub fn align(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { } Value::template(move |ctx| { - let snapshot = ctx.state.clone(); - if let Some(horizontal) = horizontal { ctx.state.aligns.cross = horizontal.to_align(ctx.state.lang.dir); } if let Some(vertical) = vertical { - ctx.state.aligns.main = vertical.to_align(Dir::TTB); - if ctx.state.aligns.main != snapshot.aligns.main { + let new = vertical.to_align(Dir::TTB); + if ctx.state.aligns.main != new { + ctx.state.aligns.main = new; ctx.parbreak(); } } - if let Some(body) = &body { - body.exec(ctx); - ctx.state = snapshot; - } + body.exec(ctx); }) } diff --git a/src/library/text.rs b/src/library/text.rs index 6a2fe9bb..28ca2bd8 100644 --- a/src/library/text.rs +++ b/src/library/text.rs @@ -17,10 +17,9 @@ pub fn font(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { let serif = args.named(ctx, "serif"); let sans_serif = args.named(ctx, "sans-serif"); let monospace = args.named(ctx, "monospace"); - let body = args.eat::<TemplateValue>(ctx); + let body = args.expect::<TemplateValue>(ctx, "body").unwrap_or_default(); Value::template(move |ctx| { - let snapshot = ctx.state.clone(); let font = ctx.state.font_mut(); if let Some(linear) = size { @@ -67,10 +66,7 @@ pub fn font(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { font.families_mut().monospace = monospace.clone(); } - if let Some(body) = &body { - body.exec(ctx); - ctx.state = snapshot; - } + body.exec(ctx); }) } @@ -161,6 +157,7 @@ pub fn par(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { let spacing = args.named(ctx, "spacing"); let leading = args.named(ctx, "leading"); let word_spacing = args.named(ctx, "word-spacing"); + let body = args.expect::<TemplateValue>(ctx, "body").unwrap_or_default(); Value::template(move |ctx| { if let Some(spacing) = spacing { @@ -176,6 +173,7 @@ pub fn par(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { } ctx.parbreak(); + body.exec(ctx); }) } @@ -190,6 +188,7 @@ pub fn lang(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { } None => None, }; + let body = args.expect::<TemplateValue>(ctx, "body").unwrap_or_default(); Value::template(move |ctx| { if let Some(dir) = dir.or(iso) { @@ -197,6 +196,7 @@ pub fn lang(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { } ctx.parbreak(); + body.exec(ctx); }) } @@ -232,7 +232,7 @@ fn line_impl( let position = args.named(ctx, "position"); let strength = args.named::<Linear>(ctx, "strength"); let extent = args.named(ctx, "extent").unwrap_or_default(); - let body = args.eat::<TemplateValue>(ctx); + let body = args.expect::<TemplateValue>(ctx, "body").unwrap_or_default(); // Suppress any existing strikethrough if strength is explicitly zero. let state = strength.map_or(true, |s| !s.is_zero()).then(|| { @@ -245,13 +245,7 @@ fn line_impl( }); Value::template(move |ctx| { - let snapshot = ctx.state.clone(); - *substate(ctx.state.font_mut()) = state.clone(); - - if let Some(body) = &body { - body.exec(ctx); - ctx.state = snapshot; - } + body.exec(ctx); }) } |
