id mapping

This commit is contained in:
Emile Bangma 2025-04-02 20:58:21 +00:00 committed by GitHub
parent ecaec9b8cb
commit e0eb38c4fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -82,17 +82,15 @@ async function mouseEnterHandler(
const contents = await response.text() const contents = await response.text()
const html = p.parseFromString(contents, "text/html") const html = p.parseFromString(contents, "text/html")
normalizeRelativeURLs(html, targetUrl) normalizeRelativeURLs(html, targetUrl)
// strip all IDs from elements to prevent duplicates on same-page links // prepend all IDs inside popovers to prevent duplicates
if (thisUrl.pathname === targetUrl.pathname) { html.querySelectorAll("[id]").forEach((el) => {
html.querySelectorAll("[id]").forEach((el) => { const targetID = `popover-${el.id}`
const targetID = `popover-${el.id}` const targetLink = hash.startsWith("#popover")
const targetLink = hash.startsWith("#popover") ? hash
? hash : `#popover-${hash.slice(1).replace("^", "").replace("%5E", "")}`
: `#popover-${hash.slice(1).replace("^", "").replace("%5E", "")}` el.id = targetID
el.id = targetID hash = targetLink
hash = targetLink })
})
}
const elts = [...html.getElementsByClassName("popover-hint")] const elts = [...html.getElementsByClassName("popover-hint")]
if (elts.length === 0) return if (elts.length === 0) return