From 578b2b336853e833621bfe2c007747d532c446f4 Mon Sep 17 00:00:00 2001 From: Emile Bangma Date: Wed, 2 Apr 2025 12:48:54 +0000 Subject: [PATCH] fix(popover): automatically position heading links at heading --- quartz/components/scripts/popover.inline.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/quartz/components/scripts/popover.inline.ts b/quartz/components/scripts/popover.inline.ts index 733779369..1487b1fb7 100644 --- a/quartz/components/scripts/popover.inline.ts +++ b/quartz/components/scripts/popover.inline.ts @@ -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