From 4f5242ef1399aba8191daf2617620eb037f6e22b Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Sun, 12 Apr 2020 04:14:30 -0600 Subject: [PATCH] build TOC entries using text-only content --- src/js/02-on-this-page.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/js/02-on-this-page.js b/src/js/02-on-this-page.js index 5ee7b80..6b78652 100644 --- a/src/js/02-on-this-page.js +++ b/src/js/02-on-this-page.js @@ -16,10 +16,8 @@ var lastActiveFragment var links = {} var list = headings.reduce(function (accum, heading) { - var link = toArray(heading.childNodes).reduce(function (target, child) { - if (child.nodeName !== 'A') target.appendChild(child.cloneNode(true)) - return target - }, document.createElement('a')) + var link = document.createElement('a') + link.textContent = heading.textContent links[(link.href = '#' + heading.id)] = link var listItem = document.createElement('li') listItem.dataset.level = parseInt(heading.nodeName.slice(1)) - 1 @@ -97,11 +95,7 @@ } function find (selector, from) { - return toArray((from || document).querySelectorAll(selector)) - } - - function toArray (collection) { - return [].slice.call(collection) + return [].slice.call((from || document).querySelectorAll(selector)) } function getNumericStyleVal (el, prop) { -- 2.11.0