Skip to content

Commit 8ec8365

Browse files
committed
Fix avoiding the mark header in the sidebar nav
This makes sure that the sidebar headings don't have the `<mark>` tag. When these are created, the Marker is unable to remove them from the sidebar (and we don't want them there in the first place). I suspect we'll want more filtering in the future, but I'm not sure exactly what to filter. Alternatively, it could have an allow list of tags, and filter all others out.
1 parent 49f9be8 commit 8ec8365

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

crates/mdbook-html/front-end/templates/toc.js.hbs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,16 @@ window.customElements.define('mdbook-sidebar-scrollbox', MDBookSidebarScrollbox)
327327
});
328328
}
329329
330+
// Takes the nodes from the given head and copies them over to the
331+
// destination, along with some filtering.
332+
function filterHeader(source, dest) {
333+
const clone = source.cloneNode(true);
334+
clone.querySelectorAll('mark').forEach(mark => {
335+
mark.replaceWith(...mark.childNodes);
336+
});
337+
dest.append(...clone.childNodes);
338+
}
339+
330340
// Scans page for headers and adds them to the sidebar.
331341
document.addEventListener('DOMContentLoaded', function() {
332342
const activeSection = document.querySelector('#mdbook-sidebar .active');
@@ -399,7 +409,7 @@ window.customElements.define('mdbook-sidebar-scrollbox', MDBookSidebarScrollbox)
399409
span.appendChild(a);
400410
a.href = '#' + header.id;
401411
a.classList.add('header-in-summary');
402-
a.innerHTML = header.children[0].innerHTML;
412+
filterHeader(header.children[0], a);
403413
a.addEventListener('click', headerThresholdClick);
404414
const nextHeader = headers[i + 1];
405415
if (nextHeader !== undefined) {

tests/gui/heading-nav-filter.goml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
set-window-size: (1400, 800)
44
go-to: |DOC_PATH| + "heading-nav/filtered-headings.html?highlight=skateboard#skateboard"
55

6-
assert-property: ("//a[contains(@class, 'header-in-summary') and @href='#skateboard']", {"innerHTML": '<mark data-markjs="true">Skateboard</mark>'})
6+
assert-property: ("//a[contains(@class, 'header-in-summary') and @href='#skateboard']", {"innerHTML": 'Skateboard'})

0 commit comments

Comments
 (0)