Skip to content

Commit 193d941

Browse files
committed
fix: patch for docsify-ignore
1 parent 8b7dbaa commit 193d941

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

docs/more-pages.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,24 +114,24 @@ A custom sidebar can also automatically generate a table of contents by setting
114114

115115
## Ignoring Subheaders
116116

117-
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.
117+
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.
118118

119119
```markdown
120120
# Getting Started
121121

122-
## Header {docsify-ignore}
122+
## Header <!-- {docsify-ignore} -->
123123

124124
This header won't appear in the sidebar table of contents.
125125
```
126126

127-
To ignore all headers on a specific page, you can use `{docsify-ignore-all}` on the first header of the page.
127+
To ignore all headers on a specific page, you can use `<!-- {docsify-ignore-all} -->` on the first header of the page.
128128

129129
```markdown
130-
# Getting Started {docsify-ignore-all}
130+
# Getting Started <!-- {docsify-ignore-all} -->
131131

132132
## Header
133133

134134
This header won't appear in the sidebar table of contents.
135135
```
136136

137-
Both `{docsify-ignore}` and `{docsify-ignore-all}` will not be rendered on the page when used.
137+
Both `<!-- {docsify-ignore} -->` and `<!-- {docsify-ignore-all} -->` will not be rendered on the page when used.

src/core/render/compiler.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,24 @@ export class Compiler {
214214
nextToc.ignoreSubHeading = true;
215215
}
216216

217+
if (/<!-- {docsify-ignore} -->/g.test(str)) {
218+
str = str.replace('<!-- {docsify-ignore} -->', '');
219+
nextToc.title = str;
220+
nextToc.ignoreSubHeading = true;
221+
}
222+
217223
if (/{docsify-ignore-all}/g.test(str)) {
218224
str = str.replace('{docsify-ignore-all}', '');
219225
nextToc.title = str;
220226
nextToc.ignoreAllSubs = true;
221227
}
222228

229+
if (/<!-- {docsify-ignore-all} -->/g.test(str)) {
230+
str = str.replace('<!-- {docsify-ignore-all} -->', '');
231+
nextToc.title = str;
232+
nextToc.ignoreAllSubs = true;
233+
}
234+
223235
const slug = slugify(config.id || str);
224236
const url = router.toURL(router.getCurrentPath(), { id: slug });
225237
nextToc.slug = url;

src/core/render/compiler/headline.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,24 @@ export const headingCompiler = ({ renderer, router, _self }) =>
1212
nextToc.ignoreSubHeading = true;
1313
}
1414

15+
if (/<!-- {docsify-ignore} -->/g.test(str)) {
16+
str = str.replace('<!-- {docsify-ignore} -->', '');
17+
nextToc.title = str;
18+
nextToc.ignoreSubHeading = true;
19+
}
20+
1521
if (/{docsify-ignore-all}/g.test(str)) {
1622
str = str.replace('{docsify-ignore-all}', '');
1723
nextToc.title = str;
1824
nextToc.ignoreAllSubs = true;
1925
}
2026

27+
if (/<!-- {docsify-ignore-all} -->/g.test(str)) {
28+
str = str.replace('<!-- {docsify-ignore-all} -->', '');
29+
nextToc.title = str;
30+
nextToc.ignoreAllSubs = true;
31+
}
32+
2133
const slug = slugify(config.id || str);
2234
const url = router.toURL(router.getCurrentPath(), { id: slug });
2335
nextToc.slug = url;

test/unit/render.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,22 @@ describe('render', function() {
266266
);
267267
});
268268

269+
it('ignore-html-comments', async function() {
270+
const { docsify } = await init();
271+
const output = docsify.compiler.compile(
272+
'## h2 tag <!-- {docsify-ignore} -->'
273+
);
274+
expectSameDom(
275+
output,
276+
`
277+
<h2 id="h2-tag">
278+
<a href="#/?id=h2-tag" data-id="h2-tag" class="anchor">
279+
<span>h2 tag </span>
280+
</a>
281+
</h2>`
282+
);
283+
});
284+
269285
it('ignore-all', async function() {
270286
const { docsify } = await init();
271287
const output = docsify.compiler.compile(
@@ -286,6 +302,27 @@ describe('render', function() {
286302
</h2>`
287303
);
288304
});
305+
306+
it('ignore-all-html-comments', async function() {
307+
const { docsify } = await init();
308+
const output = docsify.compiler.compile(
309+
`# h1 tag <!-- {docsify-ignore-all} -->` + `\n## h2 tag`
310+
);
311+
expectSameDom(
312+
output,
313+
`
314+
<h1 id="h1-tag">
315+
<a href="#/?id=h1-tag" data-id="h1-tag" class="anchor">
316+
<span>h1 tag </span>
317+
</a>
318+
</h1>
319+
<h2 id="h2-tag">
320+
<a href="#/?id=h2-tag" data-id="h2-tag" class="anchor">
321+
<span>h2 tag</span>
322+
</a>
323+
</h2>`
324+
);
325+
});
289326
});
290327

291328
describe('link', function() {

0 commit comments

Comments
 (0)