Skip to content

Commit 1be912e

Browse files
authored
Ensure only heading element text is used (#328)
This PR is required by a future change to how roles on headings are handled. Currently labels are processed by javascript when a page is loaded in a browser. We are adding an extension to convert roles into labels during the asciidoc to html conversion so that their metadata (dataset attributes) are part of the raw HTML and can be used by tools that parse the HTML. This PR ensures that only the text content of the heading element is used for the entries in the 'Contents' nav section of a page.
1 parent d4f7016 commit 1be912e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/js/02-on-this-page.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
var selectors = document.querySelector('.nav-container .selectors')
1313
var selectorsHeight = selectors ? selectors.getBoundingClientRect().height : 0
1414
var headingSelector = []
15-
for (var l = 0; l <= levels; l++) headingSelector.push(l ? '.sect' + l + '>h' + (l + 1) + '[id]' : 'h1[id].sect0')
15+
for (var l = 0; l <= levels; l++) headingSelector.push(l ? '.sect' + l + ':not(.discrete)>h' + (l + 1) + '[id]' : 'h1[id].sect0')
1616
var headings = find(headingSelector.join(','), article)
1717

1818
var menu = sidebar.querySelector('.toc-menu-placeholder')
@@ -29,7 +29,9 @@
2929
var links = {}
3030
var list = headings.reduce(function (accum, heading) {
3131
var link = document.createElement('a')
32-
link.textContent = heading.textContent
32+
var headingClone = heading.cloneNode(true)
33+
headingClone.querySelectorAll('div, a').forEach(function (el) { el.remove() })
34+
link.innerHTML = headingClone.innerHTML
3335
links[(link.href = '#' + heading.id)] = link
3436
var listItem = document.createElement('li')
3537
listItem.dataset.level = parseInt(heading.nodeName.slice(1)) - 1

0 commit comments

Comments
 (0)