diff options
author | olOwOlo <26087907+olOwOlo@users.noreply.github.com> | 2017-11-01 22:55:58 +0800 |
---|---|---|
committer | olOwOlo <26087907+olOwOlo@users.noreply.github.com> | 2017-11-01 22:55:58 +0800 |
commit | c01c9cffb711cf3c647e68fdb417a505aa44c784 (patch) | |
tree | 453b8a4ff59e8a5ec8b3d29a9e347331a52b905d /src/js | |
parent | 8cd3af63317fda36bd9ba6c4c128e0c17c4dbb39 (diff) |
feat: remove excess `ul` when the title is not starting from `h1`
release 2.6.5
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/even.js | 12 |
1 files changed, 12 insertions, 0 deletions
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' |