diff --git a/library/src/text/mod.rs b/library/src/text/mod.rs index 1ab1c37d8..6cf1e1c53 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 { + 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 16c1eab4f..ff9905f65 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 e901b488d..1d343345d 100644 Binary files a/tests/ref/style/show-text.png and b/tests/ref/style/show-text.png differ diff --git a/tests/typ/style/show-text.typ b/tests/typ/style/show-text.typ index 457ce9b7e..138b9b02e 100644 --- a/tests/typ/style/show-text.typ +++ b/tests/typ/style/show-text.typ @@ -47,6 +47,11 @@ Treeworld, the World of worlds, is a world. #show regex("(?i)rust"): it => [#it (🚀)] 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 => [