summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-21 17:12:16 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-21 17:12:16 +0100
commitdd9c323941260a1d08d5113dbefa023713f553da (patch)
tree48c813c01a83f5c6ca67ebbabd041c0298eb0da2
parentc28d2130ddda3ae9b25cc16c3015087990ccb6e9 (diff)
Show with set
-rw-r--r--src/model/eval.rs6
-rw-r--r--src/model/styles.rs3
-rw-r--r--src/syntax/incremental.rs2
-rw-r--r--tests/typ/structure/attach.typ2
-rw-r--r--tests/typ/style/construct.typ2
-rw-r--r--tests/typ/style/label.typ8
-rw-r--r--tests/typ/style/show-node.typ2
-rw-r--r--tests/typ/style/show-selector.typ6
-rw-r--r--tests/typ/text/indent.typ2
-rw-r--r--tests/typ/text/par.typ11
10 files changed, 25 insertions, 19 deletions
diff --git a/src/model/eval.rs b/src/model/eval.rs
index 79ad0815..b7df12aa 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::<Transform>().at(span)?;
+
+ let transform = match transform {
+ ast::Expr::Set(set) => Transform::Style(set.eval(vm)?),
+ expr => expr.eval(vm)?.cast::<Transform>().at(span)?,
+ };
Ok(Recipe { span, selector, transform })
}
diff --git a/src/model/styles.rs b/src/model/styles.rs
index 4195d3e1..30db00bd 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 1087bb79..6c9145a2 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 c13de236..9d043eb0 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 be11e97e..f535184c 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 0b667783..3ce0c02c 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 <intro>
@@ -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 <last>] 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* <red> *C* <blue> *D*
diff --git a/tests/typ/style/show-node.typ b/tests/typ/style/show-node.typ
index 51b4734e..0124e61c 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 ed8c0d8e..0e9823a5 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 b2f3d87b..8454dda5 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 56a33577..558059e9 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() {}