diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index 669b6226f..2978a9f26 100644 --- a/src/core/render/compiler.js +++ b/src/core/render/compiler.js @@ -214,12 +214,24 @@ export class Compiler { nextToc.ignoreSubHeading = true; } + if (/{docsify-ignore}/g.test(str)) { + str = str.replace('{docsify-ignore}', ''); + nextToc.title = str; + nextToc.ignoreSubHeading = true; + } + if (//g.test(str)) { str = str.replace('', ''); nextToc.title = str; nextToc.ignoreAllSubs = true; } + if (/{docsify-ignore-all}/g.test(str)) { + str = str.replace('{docsify-ignore-all}', ''); + nextToc.title = str; + nextToc.ignoreAllSubs = true; + } + const slug = slugify(config.id || str); const url = router.toURL(router.getCurrentPath(), { id: slug }); nextToc.slug = url; diff --git a/src/core/render/compiler/headline.js b/src/core/render/compiler/headline.js index cfbad7b25..48ae9e8c9 100644 --- a/src/core/render/compiler/headline.js +++ b/src/core/render/compiler/headline.js @@ -12,12 +12,24 @@ export const headingCompiler = ({ renderer, router, _self }) => nextToc.ignoreSubHeading = true; } + if (/{docsify-ignore}/g.test(str)) { + str = str.replace('{docsify-ignore}', ''); + nextToc.title = str; + nextToc.ignoreSubHeading = true; + } + if (//g.test(str)) { str = str.replace('', ''); nextToc.title = str; nextToc.ignoreAllSubs = true; } + if (/{docsify-ignore-all}/g.test(str)) { + str = str.replace('{docsify-ignore-all}', ''); + nextToc.title = str; + nextToc.ignoreAllSubs = true; + } + const slug = slugify(config.id || str); const url = router.toURL(router.getCurrentPath(), { id: slug }); nextToc.slug = url; diff --git a/test/unit/render.test.js b/test/unit/render.test.js index 43a87248d..fe5bade7f 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, ` @@ -268,10 +266,26 @@ describe('render', function() { ); }); + it('ignore-html-comments', async function() { + const { docsify } = await init(); + const output = docsify.compiler.compile( + '## h2 tag ignore ' + ); + expectSameDom( + output, + ` +

+ + h2 tag ignore + +

` + ); + }); + 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, @@ -288,6 +302,27 @@ describe('render', function() { ` ); }); + + it('ignore-all-html-comments', async function() { + const { docsify } = await init(); + const output = docsify.compiler.compile( + `# h1 tag ignore ` + `\n## h2 tag` + ); + expectSameDom( + output, + ` +

+ + h1 tag ignore + +

+

+ + h2 tag + +

` + ); + }); }); describe('link', function() {