Pass text node to text show rule instead of string

This commit is contained in:
Laurenz 2022-11-18 14:31:51 +01:00
parent 92f2c56203
commit 9b8c1dc19f
4 changed files with 16 additions and 3 deletions

View File

@ -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 {

View File

@ -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();
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 46 KiB

View File

@ -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 => [