diff --git a/docs/more-pages.md b/docs/more-pages.md index 59ceb33de..dbe2e7f9c 100644 --- a/docs/more-pages.md +++ b/docs/more-pages.md @@ -68,3 +68,25 @@ A custom sidebar can also automatically generate a table of contents by setting ``` + +## Ignoring Subheaders + +When `subMaxLevel` is set, each header is automatically added to the table of contents by default. If you want to ignore a specific header, add `{docsify-ignore}` to it. + +```markdown +# Getting Started + +## Header {docsify-ignore} +This header won't appear in the sidebar table of contents. +``` + +To ignore all headers on a specific page, you can use `{docsify-ignore-all}` on the first header of the page. + +```markdown +# Getting Started {docsify-ignore-all} + +## Header +This header won't appear in the sidebar table of contents. +``` + +Both `{docsify-ignore}` and `{docsify-ignore-all}` will not be rendered on the page when used. diff --git a/lib/docsify.js b/lib/docsify.js index 7b60b40fb..e76a23f10 100644 --- a/lib/docsify.js +++ b/lib/docsify.js @@ -2992,10 +2992,24 @@ markdown.update = function () { * @link https://github.com/chjj/marked#overriding-renderer-methods */ renderer.heading = function (text, level) { + var nextToc = { level: level, title: text }; + + if (/{docsify-ignore}/g.test(text)) { + text = text.replace('{docsify-ignore}',''); + nextToc.title = text; + nextToc.ignoreSubHeading = true; + } + + if (/{docsify-ignore-all}/g.test(text)) { + text = text.replace('{docsify-ignore-all}',''); + nextToc.title = text; + nextToc.ignoreAllSubs = true; + } + var slug = slugify(text); var url = toURL(currentPath, { id: slug }); - - toc.push({ level: level, slug: url, title: text }); + nextToc.slug = url; + toc.push(nextToc); return ("" + text + "") }; @@ -3017,7 +3031,7 @@ renderer.link = function (href, title, text) { if (title) { title = " title=\"" + title + "\""; } - return ("" + text + "") + return ("" + text + "") }; renderer.paragraph = function (text) { if (/^!>/.test(text)) { @@ -3061,7 +3075,11 @@ function sidebar (text, level) { */ function subSidebar (el, level) { if (el) { + toc[0] && toc[0].ignoreAllSubs && (toc = []); toc[0] && toc[0].level === 1 && toc.shift(); + toc.forEach(function (node, i) { + node.ignoreSubHeading && toc.splice(i, 1); + }); var tree$$1 = cacheTree[currentPath] || genTree(toc, level); el.parentNode.innerHTML += tree(tree$$1, '