From 90d283d340502456a5d8495df596bb4a02ceb39b Mon Sep 17 00:00:00 2001 From: Mattia Astorino Date: Thu, 30 Jul 2020 12:11:04 +0200 Subject: [PATCH] fix: convert {docsify-ignore} and {docsify-ignore-all} to HTML comments (#1318) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * breaking: convert {docsify-ignore} and {docsify-ignore-all} to HTML comments Close https://github.com/docsifyjs/docsify/issues/441 * chore: add ignore and ignore-all unit tests Co-authored-by: 沈唁 <52o@qq52o.cn> --- docs/more-pages.md | 10 ++++---- src/core/render/compiler.js | 8 +++--- src/core/render/compiler/headline.js | 8 +++--- test/unit/render.test.js | 37 ++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 13 deletions(-) diff --git a/docs/more-pages.md b/docs/more-pages.md index 429eaf97a..0f9386848 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 `{docsify-ignore}` 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 `` to it. ```markdown # Getting Started -## Header {docsify-ignore} +## Header 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. +To ignore all headers on a specific page, you can use `` on the first header of the page. ```markdown -# Getting Started {docsify-ignore-all} +# Getting Started ## 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. +Both `` and `` will not be rendered on the page when used. diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index 4eaf51215..669b6226f 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 (/{docsify-ignore}/g.test(str)) { - str = str.replace('{docsify-ignore}', ''); + if (//g.test(str)) { + str = str.replace('', ''); nextToc.title = str; nextToc.ignoreSubHeading = true; } - if (/{docsify-ignore-all}/g.test(str)) { - str = str.replace('{docsify-ignore-all}', ''); + if (//g.test(str)) { + str = str.replace('', ''); nextToc.title = str; nextToc.ignoreAllSubs = true; } diff --git a/src/core/render/compiler/headline.js b/src/core/render/compiler/headline.js index 3f5c22039..cfbad7b25 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 (/{docsify-ignore}/g.test(str)) { - str = str.replace('{docsify-ignore}', ''); + if (//g.test(str)) { + str = str.replace('', ''); nextToc.title = str; nextToc.ignoreSubHeading = true; } - if (/{docsify-ignore-all}/g.test(str)) { - str = str.replace('{docsify-ignore-all}', ''); + if (//g.test(str)) { + str = str.replace('', ''); nextToc.title = str; nextToc.ignoreAllSubs = true; } diff --git a/test/unit/render.test.js b/test/unit/render.test.js index 28e88ac0e..43a87248d 100644 --- a/test/unit/render.test.js +++ b/test/unit/render.test.js @@ -251,6 +251,43 @@ describe('render', function() { ` ); }); + + it('ignore', async function() { + const { docsify } = await init(); + const output = docsify.compiler.compile( + '## h2 tag ' + ); + expectSameDom( + output, + ` +

+ + h2 tag + +

` + ); + }); + + it('ignore-all', async function() { + const { docsify } = await init(); + const output = docsify.compiler.compile( + `# h1 tag ` + `\n## h2 tag` + ); + expectSameDom( + output, + ` +

+ + h1 tag + +

+

+ + h2 tag + +

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