From ce316075e033afdbeb43ce01e284a29fe1870e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=94=81?= <52o@qq52o.cn> Date: Sat, 22 Aug 2020 19:24:56 +0800 Subject: [PATCH] fix : add patch for {docsify-ignore} and {docsify-ignore-all} (#1351) * revert: Convert {docsify-ignore} and {docsify-ignore-all} to HTML comments This reverts commit 90d283d340502456a5d8495df596bb4a02ceb39b * fix: patch for docsify-ignore * fix test * fix test --- src/core/render/compiler.js | 12 ++++++++ src/core/render/compiler/headline.js | 12 ++++++++ test/unit/render.test.js | 43 +++++++++++++++++++++++++--- 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index 669b6226..2978a9f2 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 cfbad7b2..48ae9e8c 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 43a87248..fe5bade7 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, + ` +