Bauke/cv
Bauke
/
cv
1
Fork 0

Add the content_to_string utility.

This commit is contained in:
Bauke 2024-01-06 15:46:39 +01:00
parent 5941e228b4
commit f0167c0e64
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 15 additions and 0 deletions

View File

@ -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 == [ ] {
" "
}
}