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
This commit is contained in:
沈唁 2020-08-22 19:24:56 +08:00 committed by GitHub
parent ef32da1dcf
commit ce316075e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 4 deletions

View File

@ -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 (/<!-- {docsify-ignore-all} -->/g.test(str)) {
str = str.replace('<!-- {docsify-ignore-all} -->', '');
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;

View File

@ -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 (/<!-- {docsify-ignore-all} -->/g.test(str)) {
str = str.replace('<!-- {docsify-ignore-all} -->', '');
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;

View File

@ -254,9 +254,7 @@ describe('render', function() {
it('ignore', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile(
'## h2 tag <!-- {docsify-ignore} -->'
);
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 <!-- {docsify-ignore} -->'
);
expectSameDom(
output,
`
<h2 id="h2-tag-ignore">
<a href="#/?id=h2-tag-ignore" data-id="h2-tag-ignore" class="anchor">
<span>h2 tag ignore </span>
</a>
</h2>`
);
});
it('ignore-all', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile(
`# h1 tag <!-- {docsify-ignore-all} -->` + `\n## h2 tag`
`# h1 tag {docsify-ignore-all}` + `\n## h2 tag`
);
expectSameDom(
output,
@ -288,6 +302,27 @@ describe('render', function() {
</h2>`
);
});
it('ignore-all-html-comments', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile(
`# h1 tag ignore <!-- {docsify-ignore-all} -->` + `\n## h2 tag`
);
expectSameDom(
output,
`
<h1 id="h1-tag-ignore">
<a href="#/?id=h1-tag-ignore" data-id="h1-tag-ignore" class="anchor">
<span>h1 tag ignore </span>
</a>
</h1>
<h2 id="h2-tag">
<a href="#/?id=h2-tag" data-id="h2-tag" class="anchor">
<span>h2 tag</span>
</a>
</h2>`
);
});
});
describe('link', function() {