Skip to content

Commit

Permalink
fix: improve plain-text (#57)
Browse files Browse the repository at this point in the history
* fix #55: improve `plain-text`

* fix: store local variables for performance & readability
  • Loading branch information
ice1000 committed Mar 31, 2024
1 parent 30f19ab commit 5d03031
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions contrib/typst/book/lib.typ
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,26 @@

// Collect text content of element recursively into a single string
// https://discord.com/channels/1054443721975922748/1088371919725793360/1138586827708702810
// https://github.com/Myriad-Dreamin/typst-book/issues/55
#let _styled = smallcaps("").func();
#let _equation = $1$.func();
#let _sequence = [].func();
#let plain-text(it) = {
if type(it) == str {
it
return it
} else if it == [ ] {
" "
} else if it.func() == text or it.func() == raw {
return " "
}
let f = it.func()
if f == _styled {
plain-text(it.child)
} else if f == _equation {
plain-text(it.body)
} else if f == text or f == raw {
it.text
} else if it.func() == smartquote {
} else if f == smartquote {
if it.double { "\"" } else { "'" }
} else if it.func() == [].func() {
} else if f == _sequence {
it.children.map(plain-text).filter(t => type(t) == str).join()
} else {
none
Expand Down

0 comments on commit 5d03031

Please sign in to comment.