From c01c9cffb711cf3c647e68fdb417a505aa44c784 Mon Sep 17 00:00:00 2001 From: olOwOlo <26087907+olOwOlo@users.noreply.github.com> Date: Wed, 1 Nov 2017 22:55:58 +0800 Subject: feat: remove excess `ul` when the title is not starting from `h1` release 2.6.5 --- src/js/even.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/js') diff --git a/src/js/even.js b/src/js/even.js index 783698a..974346e 100644 --- a/src/js/even.js +++ b/src/js/even.js @@ -160,12 +160,24 @@ Even.toc = function () { // toc = true, but there are no headings tocContainer.parentNode.removeChild(tocContainer) } else { + this._refactorToc(toc) this._linkToc() this._initToc() } } } +Even._refactorToc = function (toc) { + const oldTocList = toc.children[0] + let newTocList = oldTocList + let temp + while (newTocList.children.length === 1 && (temp = newTocList.children[0].children[0]).tagName === 'UL') + newTocList = temp + + if (newTocList !== oldTocList) + toc.replaceChild(newTocList, oldTocList) +} + Even._linkToc = function () { const links = document.querySelectorAll('#TableOfContents a') for (let i = 0; i < links.length; i++) links[i].className += ' toc-link' -- cgit v1.2.3