fix: only target text links for 'internal' class prepend
This commit is contained in:
parent
7bc66067e6
commit
63a7b9d666
1 changed files with 18 additions and 1 deletions
|
|
@ -3,9 +3,26 @@
|
||||||
#show link: it => {
|
#show link: it => {
|
||||||
let dest = it.dest
|
let dest = it.dest
|
||||||
if type(dest) == str {
|
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 is-internal = dest.starts-with("/") or dest.starts-with(".")
|
||||||
let attrs = (href: dest)
|
let attrs = (href: dest)
|
||||||
if is-internal {
|
if is-internal and is-text-only(it.body) {
|
||||||
attrs = (href: dest, class: "internal")
|
attrs = (href: dest, class: "internal")
|
||||||
}
|
}
|
||||||
html.elem("a", attrs: attrs, it.body)
|
html.elem("a", attrs: attrs, it.body)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue