fix(popover): automatically position heading links at heading

This commit is contained in:
Emile Bangma 2025-04-02 12:48:54 +00:00 committed by GitHub
parent f334e78ed6
commit 578b2b3368
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -82,8 +82,10 @@ async function mouseEnterHandler(
const contents = await response.text()
const html = p.parseFromString(contents, "text/html")
normalizeRelativeURLs(html, targetUrl)
// strip all IDs from elements to prevent duplicates
html.querySelectorAll("[id]").forEach((el) => el.removeAttribute("id"))
// strip all IDs from non-heading elements
html
.querySelectorAll("[id]:not(:is(h1, h2, h3, h4, h5, h6))")
.forEach((el) => el.removeAttribute("id"))
const elts = [...html.getElementsByClassName("popover-hint")]
if (elts.length === 0) return