diff --git a/docs/more-pages.md b/docs/more-pages.md index 0f9386848..429eaf97a 100644 --- a/docs/more-pages.md +++ b/docs/more-pages.md @@ -114,24 +114,24 @@ 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 `` to it. +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 +## 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 `` on the first header of the page. +To ignore all headers on a specific page, you can use `{docsify-ignore-all}` on the first header of the page. ```markdown -# Getting Started +# Getting Started {docsify-ignore-all} ## Header This header won't appear in the sidebar table of contents. ``` -Both `` and `` will not be rendered on the page when used. +Both `{docsify-ignore}` and `{docsify-ignore-all}` will not be rendered on the page when used. diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index 669b6226f..4eaf51215 100644 --- a/src/core/render/compiler.js +++ b/src/core/render/compiler.js @@ -208,14 +208,14 @@ export class Compiler { let { str, config } = getAndRemoveConfig(text); const nextToc = { level, title: str }; - if (//g.test(str)) { - str = str.replace('', ''); + if (/{docsify-ignore}/g.test(str)) { + str = str.replace('{docsify-ignore}', ''); nextToc.title = str; nextToc.ignoreSubHeading = true; } - if (//g.test(str)) { - str = str.replace('', ''); + if (/{docsify-ignore-all}/g.test(str)) { + str = str.replace('{docsify-ignore-all}', ''); nextToc.title = str; nextToc.ignoreAllSubs = true; } diff --git a/src/core/render/compiler/headline.js b/src/core/render/compiler/headline.js index cfbad7b25..3f5c22039 100644 --- a/src/core/render/compiler/headline.js +++ b/src/core/render/compiler/headline.js @@ -6,14 +6,14 @@ export const headingCompiler = ({ renderer, router, _self }) => let { str, config } = getAndRemoveConfig(text); const nextToc = { level, title: str }; - if (//g.test(str)) { - str = str.replace('', ''); + if (/{docsify-ignore}/g.test(str)) { + str = str.replace('{docsify-ignore}', ''); nextToc.title = str; nextToc.ignoreSubHeading = true; } - if (//g.test(str)) { - str = str.replace('', ''); + if (/{docsify-ignore-all}/g.test(str)) { + str = str.replace('{docsify-ignore-all}', ''); nextToc.title = str; nextToc.ignoreAllSubs = true; } diff --git a/test/unit/render.test.js b/test/unit/render.test.js index 43a87248d..c8e42798d 100644 --- a/test/unit/render.test.js +++ b/test/unit/render.test.js @@ -254,9 +254,7 @@ describe('render', function() { it('ignore', async function() { const { docsify } = await init(); - const output = docsify.compiler.compile( - '## h2 tag ' - ); + const output = docsify.compiler.compile('## h2 tag {docsify-ignore}'); expectSameDom( output, ` @@ -271,7 +269,7 @@ describe('render', function() { it('ignore-all', async function() { const { docsify } = await init(); const output = docsify.compiler.compile( - `# h1 tag ` + `\n## h2 tag` + `# h1 tag {docsify-ignore-all}` + `\n## h2 tag` ); expectSameDom( output,