From 8b7dbaa0da6fdc290b71fa20cc18f0045f484def Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Sat, 22 Aug 2020 09:30:38 +0800 Subject: [PATCH 1/4] revert: Convert {docsify-ignore} and {docsify-ignore-all} to HTML comments This reverts commit 90d283d340502456a5d8495df596bb4a02ceb39b --- docs/more-pages.md | 10 +++++----- src/core/render/compiler.js | 8 ++++---- src/core/render/compiler/headline.js | 8 ++++---- test/unit/render.test.js | 6 ++---- 4 files changed, 15 insertions(+), 17 deletions(-) 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, From 193d941b5953321e47c0592e7307312e5718986c Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Sat, 22 Aug 2020 10:29:25 +0800 Subject: [PATCH 2/4] fix: patch for docsify-ignore --- docs/more-pages.md | 10 ++++---- src/core/render/compiler.js | 12 +++++++++ src/core/render/compiler/headline.js | 12 +++++++++ test/unit/render.test.js | 37 ++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 5 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..ee0d1fa3a 100644 --- a/src/core/render/compiler.js +++ b/src/core/render/compiler.js @@ -214,12 +214,24 @@ export class Compiler { nextToc.ignoreSubHeading = true; } + 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}', ''); nextToc.title = str; nextToc.ignoreAllSubs = true; } + if (//g.test(str)) { + str = str.replace('', ''); + 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 3f5c22039..2d9f387ec 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 (//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}', ''); nextToc.title = str; nextToc.ignoreAllSubs = true; } + if (//g.test(str)) { + str = str.replace('', ''); + 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 c8e42798d..acfee6b0f 100644 --- a/test/unit/render.test.js +++ b/test/unit/render.test.js @@ -266,6 +266,22 @@ describe('render', function() { ); }); + it('ignore-html-comments', 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( @@ -286,6 +302,27 @@ describe('render', function() { ` ); }); + + it('ignore-all-html-comments', 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() { From 3b8bbd23f23ff660501448de675e1946e028a88d Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Sat, 22 Aug 2020 10:35:46 +0800 Subject: [PATCH 3/4] fix test --- test/unit/render.test.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/unit/render.test.js b/test/unit/render.test.js index acfee6b0f..263fd2093 100644 --- a/test/unit/render.test.js +++ b/test/unit/render.test.js @@ -269,14 +269,14 @@ describe('render', function() { it('ignore-html-comments', async function() { const { docsify } = await init(); const output = docsify.compiler.compile( - '## h2 tag ' + '## h2 tag ignore ' ); expectSameDom( output, ` -

- - h2 tag +

+ + h2 tag ignore

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

- - h1 tag + + h1 tag ignore

From 175bb0b1d5c41c02fc50374a01b8d71464391c83 Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Sat, 22 Aug 2020 10:45:36 +0800 Subject: [PATCH 4/4] fix test --- src/core/render/compiler.js | 16 ++++++++-------- src/core/render/compiler/headline.js | 16 ++++++++-------- test/unit/render.test.js | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index ee0d1fa3a..2978a9f26 100644 --- a/src/core/render/compiler.js +++ b/src/core/render/compiler.js @@ -208,26 +208,26 @@ 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 (//g.test(str)) { - str = str.replace('', ''); + if (/{docsify-ignore}/g.test(str)) { + str = str.replace('{docsify-ignore}', ''); 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; } - 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 2d9f387ec..48ae9e8c9 100644 --- a/src/core/render/compiler/headline.js +++ b/src/core/render/compiler/headline.js @@ -6,26 +6,26 @@ 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 (//g.test(str)) { - str = str.replace('', ''); + if (/{docsify-ignore}/g.test(str)) { + str = str.replace('{docsify-ignore}', ''); 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; } - 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 263fd2093..fe5bade7f 100644 --- a/test/unit/render.test.js +++ b/test/unit/render.test.js @@ -311,7 +311,7 @@ describe('render', function() { expectSameDom( output, ` -

+

h1 tag ignore