From ffaced98d4bc4e67047ba8ad191f00bcac83c1b0 Mon Sep 17 00:00:00 2001 From: Carlos Polop Date: Sun, 18 Jan 2026 23:17:17 +0100 Subject: [PATCH] f --- theme/pagetoc.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/theme/pagetoc.js b/theme/pagetoc.js index a51ea29ae..6bb92e7f2 100644 --- a/theme/pagetoc.js +++ b/theme/pagetoc.js @@ -31,6 +31,14 @@ const autoCreatePagetoc = () => { ) return document.querySelector(".pagetoc") } + +const getHeadingText = (heading) => { + if (!heading) return "" + const clone = heading.cloneNode(true) + const headerAnchor = clone.querySelector("a.header") + if (headerAnchor) headerAnchor.remove() + return clone.textContent.replace(/\s+/g, " ").trim() +} const updateFunction = () => { if (scrollTimeout) return // Skip updates if within the cooldown period from a click const headers = [...document.getElementsByClassName("header")] @@ -60,14 +68,12 @@ window.addEventListener("load", () => { const pagetoc = getPagetoc() const headers = [...document.getElementsByClassName("header")] headers.forEach((header) => { + const headingText = getHeadingText(header.parentElement) const link = Object.assign(document.createElement("a"), { - textContent: header.text, + textContent: headingText || header.text, href: header.href, className: `pagetoc-${header.parentElement.tagName}`, }) - if (header.parentElement.querySelectorAll("a").length === 2) { - link.textContent = header.parentElement.querySelectorAll("a")[1].text - } pagetoc.appendChild(link) }) updateFunction()