Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve plain-text #57

Merged
merged 2 commits into from
Mar 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading