fix: only target text links for 'internal' class prepend

This commit is contained in:
agryphus 2026-05-11 16:35:13 -04:00
parent 7bc66067e6
commit 63a7b9d666

View file

@ -3,9 +3,26 @@
#show link: it => {
let dest = it.dest
if type(dest) == str {
// Check if body is text-only (no images or other non-text elements)
let is-text-only(content) = {
let sequence = [a b].func()
let allowed = (text, strong, emph)
if content.func() == text { return true }
if content.func() in allowed {
if content.has("body") {
return is-text-only(content.body) // recurse into strong/emph
}
return true
}
if content.func() == sequence {
return content.children.all(c => is-text-only(c))
}
false
}
let is-internal = dest.starts-with("/") or dest.starts-with(".")
let attrs = (href: dest)
if is-internal {
if is-internal and is-text-only(it.body) {
attrs = (href: dest, class: "internal")
}
html.elem("a", attrs: attrs, it.body)