Skip to content

Commit

Permalink
fix : add patch for {docsify-ignore} and {docsify-ignore-all} (#1351)
Browse files Browse the repository at this point in the history
* revert: Convert {docsify-ignore} and {docsify-ignore-all} to HTML comments

This reverts commit 90d283d

* fix: patch for docsify-ignore

* fix test

* fix test
  • Loading branch information
sy-records committed Aug 22, 2020
1 parent ef32da1 commit ce31607
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/core/render/compiler.js
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions src/core/render/compiler/headline.js
Expand Up @@ -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;
Expand Down
43 changes: 39 additions & 4 deletions test/unit/render.test.js
Expand Up @@ -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,
`
Expand All @@ -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,
Expand All @@ -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() {
Expand Down

1 comment on commit ce31607

@vercel
Copy link

@vercel vercel bot commented on ce31607 Aug 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.