diff --git a/utilities/content-to-string.typ b/utilities/content-to-string.typ new file mode 100644 index 0000000..e0bdf64 --- /dev/null +++ b/utilities/content-to-string.typ @@ -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 == [ ] { + " " + } +}