Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix : add patch for {docsify-ignore} and {docsify-ignore-all} #1351

Merged
merged 5 commits into from
Aug 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 5 additions & 5 deletions docs/more-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,24 @@ A custom sidebar can also automatically generate a table of contents by setting

## Ignoring Subheaders

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.
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.

```markdown
# Getting Started

## Header <!-- {docsify-ignore} -->
## Header {docsify-ignore}

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

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

```markdown
# Getting Started <!-- {docsify-ignore-all} -->
# Getting Started {docsify-ignore-all}

## Header

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

Both `<!-- {docsify-ignore} -->` and `<!-- {docsify-ignore-all} -->` will not be rendered on the page when used.
Both `{docsify-ignore}` and `{docsify-ignore-all}` will not be rendered on the page when used.
8 changes: 4 additions & 4 deletions src/core/render/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,14 @@ export class Compiler {
let { str, config } = getAndRemoveConfig(text);
const nextToc = { level, title: str };

if (/<!-- {docsify-ignore} -->/g.test(str)) {
str = str.replace('<!-- {docsify-ignore} -->', '');
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} -->', '');
if (/{docsify-ignore-all}/g.test(str)) {
str = str.replace('{docsify-ignore-all}', '');
nextToc.title = str;
nextToc.ignoreAllSubs = true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/render/compiler/headline.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ export const headingCompiler = ({ renderer, router, _self }) =>
let { str, config } = getAndRemoveConfig(text);
const nextToc = { level, title: str };

if (/<!-- {docsify-ignore} -->/g.test(str)) {
str = str.replace('<!-- {docsify-ignore} -->', '');
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} -->', '');
if (/{docsify-ignore-all}/g.test(str)) {
str = str.replace('{docsify-ignore-all}', '');
nextToc.title = str;
nextToc.ignoreAllSubs = true;
}
Expand Down
6 changes: 2 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 @@ -271,7 +269,7 @@ describe('render', function() {
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 Down