Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/core/render/compiler.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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