Skip to content

Commit 46b74a7

Browse files
shorter
1 parent 376bacc commit 46b74a7

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@
2020
var links = {}
2121
var list = headings.reduce(function (accum, heading) {
2222
var link = document.createElement('a')
23-
var headingWithoutLabels = heading.cloneNode(true)
24-
if (headingWithoutLabels.querySelector('span.label') != null) {
25-
headingWithoutLabels.removeChild(headingWithoutLabels.querySelector('span.label'))
26-
}
27-
link.textContent = headingWithoutLabels.textContent
23+
var headingTextWithoutLabels = Array.from(heading.childNodes).filter((el) => el.nodeType === Node.TEXT_NODE).map((el) => el.textContent).join(' ').trim()
24+
link.textContent = headingTextWithoutLabels
2825
links[(link.href = '#' + heading.id)] = link
2926
var listItem = document.createElement('li')
3027
listItem.dataset.level = parseInt(heading.nodeName.slice(1)) - 1

0 commit comments

Comments
 (0)