Add the content_to_string utility.
This commit is contained in:
parent
5941e228b4
commit
f0167c0e64
|
@ -0,0 +1,15 @@
|
||||||
|
// Convert a `Content` type to a string by recursively going through it and
|
||||||
|
// collecting any text nodes, discarding everything else.
|
||||||
|
// Copied from GitHub:
|
||||||
|
// https://github.com/typst/typst/issues/2196#issuecomment-1728135476
|
||||||
|
#let content_to_string(content) = {
|
||||||
|
if content.has("text") {
|
||||||
|
content.text
|
||||||
|
} else if content.has("children") {
|
||||||
|
content.children.map(content_to_string).join("")
|
||||||
|
} else if content.has("body") {
|
||||||
|
content_to_string(content.body)
|
||||||
|
} else if content == [ ] {
|
||||||
|
" "
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue