Skip to content

Commit ce31607

Browse files
authored
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 90d283d * fix: patch for docsify-ignore * fix test * fix test
1 parent ef32da1 commit ce31607

File tree

3 files changed

+63
-4
lines changed

3 files changed

+63
-4
lines changed

src/core/render/compiler.js

+12
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

+12
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

+39-4
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,7 @@ describe('render', function() {
254254

255255
it('ignore', async function() {
256256
const { docsify } = await init();
257-
const output = docsify.compiler.compile(
258-
'## h2 tag <!-- {docsify-ignore} -->'
259-
);
257+
const output = docsify.compiler.compile('## h2 tag {docsify-ignore}');
260258
expectSameDom(
261259
output,
262260
`
@@ -268,10 +266,26 @@ describe('render', function() {
268266
);
269267
});
270268

269+
it('ignore-html-comments', async function() {
270+
const { docsify } = await init();
271+
const output = docsify.compiler.compile(
272+
'## h2 tag ignore <!-- {docsify-ignore} -->'
273+
);
274+
expectSameDom(
275+
output,
276+
`
277+
<h2 id="h2-tag-ignore">
278+
<a href="#/?id=h2-tag-ignore" data-id="h2-tag-ignore" class="anchor">
279+
<span>h2 tag ignore </span>
280+
</a>
281+
</h2>`
282+
);
283+
});
284+
271285
it('ignore-all', async function() {
272286
const { docsify } = await init();
273287
const output = docsify.compiler.compile(
274-
`# h1 tag <!-- {docsify-ignore-all} -->` + `\n## h2 tag`
288+
`# h1 tag {docsify-ignore-all}` + `\n## h2 tag`
275289
);
276290
expectSameDom(
277291
output,
@@ -288,6 +302,27 @@ describe('render', function() {
288302
</h2>`
289303
);
290304
});
305+
306+
it('ignore-all-html-comments', async function() {
307+
const { docsify } = await init();
308+
const output = docsify.compiler.compile(
309+
`# h1 tag ignore <!-- {docsify-ignore-all} -->` + `\n## h2 tag`
310+
);
311+
expectSameDom(
312+
output,
313+
`
314+
<h1 id="h1-tag-ignore">
315+
<a href="#/?id=h1-tag-ignore" data-id="h1-tag-ignore" class="anchor">
316+
<span>h1 tag ignore </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+
});
291326
});
292327

293328
describe('link', function() {

0 commit comments

Comments
 (0)