diff --git a/src/model/eval.rs b/src/model/eval.rs index 79ad08158..b7df12aa8 100644 --- a/src/model/eval.rs +++ b/src/model/eval.rs @@ -851,7 +851,11 @@ impl Eval for ast::ShowRule { let transform = self.transform(); let span = transform.span(); - let transform = transform.eval(vm)?.cast::().at(span)?; + + let transform = match transform { + ast::Expr::Set(set) => Transform::Style(set.eval(vm)?), + expr => expr.eval(vm)?.cast::().at(span)?, + }; Ok(Recipe { span, selector, transform }) } diff --git a/src/model/styles.rs b/src/model/styles.rs index 4195d3e1f..30db00bd3 100644 --- a/src/model/styles.rs +++ b/src/model/styles.rs @@ -491,6 +491,8 @@ pub enum Transform { Content(Content), /// A function to apply to the match. Func(Func), + /// Apply styles to the content. + Style(StyleMap), } impl Transform { @@ -512,6 +514,7 @@ impl Transform { } Ok(result?.display()) } + Transform::Style(styles) => Ok(content.styled_with_map(styles.clone())), } } } diff --git a/src/syntax/incremental.rs b/src/syntax/incremental.rs index 1087bb798..6c9145a2e 100644 --- a/src/syntax/incremental.rs +++ b/src/syntax/incremental.rs @@ -458,7 +458,7 @@ mod tests { test(r#"a ```typst hello``` b"#, 16 .. 17, "", 0 .. 18); test(r#"a ```typst hello```"#, 16 .. 17, "", 0 .. 18); test("#for", 4 .. 4, "//", 0 .. 6); - test("#show a: f as b..", 16..16, "c", 0..18); + test("#show f: a => b..", 16..16, "c", 0..18); test("a\n#let \nb", 7 .. 7, "i", 2 .. 9); test("a\n#for i \nb", 9 .. 9, "in", 2 .. 12); test("a~https://fun/html", 13..14, "n", 0..18); diff --git a/tests/typ/structure/attach.typ b/tests/typ/structure/attach.typ index c13de2366..9d043eb01 100644 --- a/tests/typ/structure/attach.typ +++ b/tests/typ/structure/attach.typ @@ -10,7 +10,7 @@ Next paragraph. --- // Test that attached list isn't affected by block spacing. -#show list: it => { set block(above: 100pt); it } +#show list: set block(above: 100pt) Hello - A World diff --git a/tests/typ/style/construct.typ b/tests/typ/style/construct.typ index be11e97eb..f535184c2 100644 --- a/tests/typ/style/construct.typ +++ b/tests/typ/style/construct.typ @@ -27,5 +27,5 @@ A #rect(fill: yellow, inset: 5pt, rect()) B --- // The constructor property should still work // when there are recursive show rules. -#show list: text.with(blue) +#show list: set text(blue) #list(label: "(a)", [A], list[B]) diff --git a/tests/typ/style/label.typ b/tests/typ/style/label.typ index 0b6677835..3ce0c02c4 100644 --- a/tests/typ/style/label.typ +++ b/tests/typ/style/label.typ @@ -2,7 +2,7 @@ --- // Test labelled headings. -#show heading: text.with(10pt) +#show heading: set text(10pt) #show heading.where(label: "intro"): underline = Introduction @@ -13,7 +13,7 @@ The end. --- // Test label after expression. -#show strong.where(label: "v"): text.with(red) +#show strong.where(label: "v"): set text(red) #let a = [*A*] #let b = [*B*] @@ -30,8 +30,8 @@ This is a thing [that ] happened. --- // Test abusing labels for styling. -#show strong.where(label: "red"): text.with(red) -#show strong.where(label: "blue"): text.with(blue) +#show strong.where(label: "red"): set text(red) +#show strong.where(label: "blue"): set text(blue) *A* *B* *C* *D* diff --git a/tests/typ/style/show-node.typ b/tests/typ/style/show-node.typ index 51b4734e9..0124e61c4 100644 --- a/tests/typ/style/show-node.typ +++ b/tests/typ/style/show-node.typ @@ -13,7 +13,7 @@ --- // Test full reset. #show heading: [B] -#show heading: text.with(size: 10pt, weight: 400) +#show heading: set text(size: 10pt, weight: 400) A [= Heading] C --- diff --git a/tests/typ/style/show-selector.typ b/tests/typ/style/show-selector.typ index ed8c0d8eb..0e9823a5f 100644 --- a/tests/typ/style/show-selector.typ +++ b/tests/typ/style/show-selector.typ @@ -28,9 +28,9 @@ code!("it"); ``` --- -#show heading.where(level: 1): text.with(red) -#show heading.where(level: 2): text.with(blue) -#show heading: text.with(green) +#show heading.where(level: 1): set text(red) +#show heading.where(level: 2): set text(blue) +#show heading: set text(green) = Red == Blue === Green diff --git a/tests/typ/text/indent.typ b/tests/typ/text/indent.typ index b2f3d87b3..8454dda5d 100644 --- a/tests/typ/text/indent.typ +++ b/tests/typ/text/indent.typ @@ -3,7 +3,7 @@ --- #set par(indent: 12pt, leading: 5pt) #set block(spacing: 5pt) -#show heading: text.with(size: 10pt) +#show heading: set text(size: 10pt) The first paragraph has no indent. diff --git a/tests/typ/text/par.typ b/tests/typ/text/par.typ index 56a33577c..558059e94 100644 --- a/tests/typ/text/par.typ +++ b/tests/typ/text/par.typ @@ -16,18 +16,17 @@ It is the east, and Juliet is the sun. --- // Test that paragraph spacing loses against block spacing. // TODO -// #set block(spacing: 100pt) -// #show table: set block(spacing: 5pt) -#set block(spacing: 5pt) +#set block(spacing: 100pt) +#show table: set block(above: 5pt, below: 5pt) Hello #table(columns: 4, fill: (x, y) => if odd(x + y) { silver })[A][B][C][D] --- // While we're at it, test the larger block spacing wins. #set block(spacing: 0pt) -#show raw: it => { set block(spacing: 15pt); it } -#show math: it => { set block(spacing: 7.5pt); it } -#show list: it => { set block(spacing: 2.5pt); it } +#show raw: set block(spacing: 15pt) +#show math: set block(spacing: 7.5pt) +#show list: set block(spacing: 2.5pt) ```rust fn main() {}