summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-18 14:31:51 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-18 14:31:51 +0100
commit9b8c1dc19fcda399f00e486460b4cc521d1a460b (patch)
tree993e6045643c63ed957d81d8a3bdf0873b1ac2bb
parent92f2c56203c6528e35ec1feae14e5dd2c2425311 (diff)
Pass text node to text show rule instead of string
-rw-r--r--library/src/text/mod.rs7
-rw-r--r--src/model/styles.rs7
-rw-r--r--tests/ref/style/show-text.pngbin44838 -> 47038 bytes
-rw-r--r--tests/typ/style/show-text.typ5
4 files changed, 16 insertions, 3 deletions
diff --git a/library/src/text/mod.rs b/library/src/text/mod.rs
index 1ab1c37d..6cf1e1c5 100644
--- a/library/src/text/mod.rs
+++ b/library/src/text/mod.rs
@@ -167,6 +167,13 @@ impl TextNode {
}
}
}
+
+ fn field(&self, name: &str) -> Option<Value> {
+ match name {
+ "text" => Some(Value::Str(self.0.clone().into())),
+ _ => None,
+ }
+ }
}
impl Debug for TextNode {
diff --git a/src/model/styles.rs b/src/model/styles.rs
index 16c1eab4..ff9905f6 100644
--- a/src/model/styles.rs
+++ b/src/model/styles.rs
@@ -419,9 +419,10 @@ impl Recipe {
result.push(make(text[cursor..start].into()));
}
- let transformed = self
- .transform
- .apply(world, self.span, || Value::Str(mat.as_str().into()))?;
+ let transformed = self.transform.apply(world, self.span, || {
+ Value::Content(make(mat.as_str().into()))
+ })?;
+
result.push(transformed);
cursor = mat.end();
}
diff --git a/tests/ref/style/show-text.png b/tests/ref/style/show-text.png
index e901b488..1d343345 100644
--- a/tests/ref/style/show-text.png
+++ b/tests/ref/style/show-text.png
Binary files differ
diff --git a/tests/typ/style/show-text.typ b/tests/typ/style/show-text.typ
index 457ce9b7..138b9b02 100644
--- a/tests/typ/style/show-text.typ
+++ b/tests/typ/style/show-text.typ
@@ -48,6 +48,11 @@ Treeworld, the World of worlds, is a world.
Rust is memory-safe and blazingly fast. Let's rewrite everything in rust.
---
+// Test accessing the string itself.
+#show "hello": it => it.text.split("").map(upper).join("|")
+Oh, hello there!
+
+---
// Replace worlds but only in lists.
#show list: it => [
#show "World": [🌎]