Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
toc: {
tocMaxLevel: 5,
target: 'h2, h3, h4, h5, h6',
ignoreHeaders: ['<!-- {docsify-ignore} -->', '<!-- {docsify-ignore-all} -->']
ignoreHeaders: ['Content', 'Job Description']
},
}
</script>
Expand Down
36 changes: 24 additions & 12 deletions src/toc.js
Original file line number Diff line number Diff line change
@@ -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 = ['<div class="page_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('</div>')
return toc.join('')
} else {
return ''
}

return ''
}

// To generate each ToC item
Expand Down