From 3930b04fda7a408f3174d7c608bf1297dfb7ce74 Mon Sep 17 00:00:00 2001 From: Sergey Kolesnik Date: Tue, 7 Nov 2023 22:05:02 +0300 Subject: [PATCH 1/2] feat: support `docsify-ignore` & `docsify-ignore-all` --- src/toc.js | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/toc.js b/src/toc.js index bca2abf..846e368 100644 --- a/src/toc.js +++ b/src/toc.js @@ -1,36 +1,48 @@ // To collect headings and then add to the page ToC -function pageToC (headings, path) { +function pageToC () { + var commentsIterator = document.createNodeIterator( + document.querySelector('#main'), + NodeFilter.SHOW_COMMENT, + ) + while(commentsIterator.nextNode()) { + var commentNode = commentsIterator.referenceNode + if (commentNode.textContent.trim() === '{docsify-ignore-all}') + return '' + } + let toc = ['
'] const list = [] const ignoreHeaders = window.$docsify.toc.ignoreHeaders || [] - headings = document.querySelectorAll(`#main ${window.$docsify.toc.target}`) + const headings = document.querySelectorAll(`#main ${window.$docsify.toc.target}`) - if (headings) { + if (headings) headings.forEach(function (heading) { const innerText = heading.innerText const innerHtml = heading.innerHTML let needSkip = false - if (ignoreHeaders.length > 0) { - console.error(innerText) + if (ignoreHeaders.length > 0) needSkip = ignoreHeaders.some(str => innerText.match(str)) - } - if (needSkip) return + const node = heading.nextSibling + if (node.nodeType === node.COMMENT_NODE && node.textContent.trim() === '{docsify-ignore}') + needSkip = true + + if (needSkip) + return const item = generateToC(heading.tagName.replace(/h/gi, ''), innerHtml) - if (item) { + if (item) list.push(item) - } }) - } + if (list.length > 0) { toc = toc.concat(list) toc.push('
') return toc.join('') - } else { - return '' } + + return '' } // To generate each ToC item From d3cc95f5a797b3fd68e1f121bafdff7f0fdb2488 Mon Sep 17 00:00:00 2001 From: Sergey Kolesnik Date: Tue, 7 Nov 2023 22:06:29 +0300 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1585aa8..2b73bbd 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ toc: { tocMaxLevel: 5, target: 'h2, h3, h4, h5, h6', - ignoreHeaders: ['', ''] + ignoreHeaders: ['Content', 'Job Description'] }, }