diff --git a/crates/mdbook-html/front-end/templates/toc.js.hbs b/crates/mdbook-html/front-end/templates/toc.js.hbs index ec77e4c0..4d0306a6 100644 --- a/crates/mdbook-html/front-end/templates/toc.js.hbs +++ b/crates/mdbook-html/front-end/templates/toc.js.hbs @@ -327,6 +327,16 @@ window.customElements.define('mdbook-sidebar-scrollbox', MDBookSidebarScrollbox) }); } + // Takes the nodes from the given head and copies them over to the + // destination, along with some filtering. + function filterHeader(source, dest) { + const clone = source.cloneNode(true); + clone.querySelectorAll('mark').forEach(mark => { + mark.replaceWith(...mark.childNodes); + }); + dest.append(...clone.childNodes); + } + // Scans page for headers and adds them to the sidebar. document.addEventListener('DOMContentLoaded', function() { const activeSection = document.querySelector('#mdbook-sidebar .active'); @@ -399,7 +409,7 @@ window.customElements.define('mdbook-sidebar-scrollbox', MDBookSidebarScrollbox) span.appendChild(a); a.href = '#' + header.id; a.classList.add('header-in-summary'); - a.innerHTML = header.children[0].innerHTML; + filterHeader(header.children[0], a); a.addEventListener('click', headerThresholdClick); const nextHeader = headers[i + 1]; if (nextHeader !== undefined) { diff --git a/tests/gui/heading-nav-filter.goml b/tests/gui/heading-nav-filter.goml index 7299833f..a42892db 100644 --- a/tests/gui/heading-nav-filter.goml +++ b/tests/gui/heading-nav-filter.goml @@ -5,4 +5,4 @@ go-to: |DOC_PATH| + "heading-nav/filtered-headings.html?highlight=skateboard#ska assert-property: ("//h2[@id='skateboard']", {"innerHTML": 'Skateboard'}) -assert-property: ("//a[contains(@class, 'header-in-summary') and @href='#skateboard']", {"innerHTML": 'Skateboard'}) +assert-property: ("//a[contains(@class, 'header-in-summary') and @href='#skateboard']", {"innerHTML": 'Skateboard'})