Skip to content

Commit

Permalink
Merge branch 'develop' into fix-1320
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records committed Jul 31, 2020
2 parents aacf61f + 9150678 commit c685754
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 17 deletions.
10 changes: 5 additions & 5 deletions docs/more-pages.md
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.
6 changes: 3 additions & 3 deletions packages/docsify-server-renderer/README.md
Expand Up @@ -14,7 +14,7 @@ var readFileSync = require('fs').readFileSync

// init
var renderer = new Renderer({
template: readFileSync('./docs/index.template.html', 'utf-8').,
template: readFileSync('./docs/index.template.html', 'utf-8'),
config: {
name: 'docsify',
repo: 'docsifyjs/docsify'
Expand All @@ -35,12 +35,12 @@ renderer.renderToString(url)
<meta charset="UTF-8">
<title>docsify</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//unpkg.com/docsify/themes/buble.css" title="buble" disabled>
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify/themes/vue.css" title="vue">
</head>
<body>
<!--inject-app-->
<!--inject-config-->
<script src="//unpkg.com/docsify/lib/docsify.js"></script>
<script src="//cdn.jsdelivr.net/npm/docsify/lib/docsify.js"></script>
</body>
</html>
```
8 changes: 4 additions & 4 deletions src/core/render/compiler.js
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
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
2 changes: 1 addition & 1 deletion src/core/router/history/hash.js
Expand Up @@ -39,7 +39,7 @@ export class HashHistory extends History {
on('click', e => {
const el = e.target.tagName === 'A' ? e.target : e.target.parentNode;

if (el.tagName === 'A' && !/_blank/.test(el.target)) {
if (el && el.tagName === 'A' && !/_blank/.test(el.target)) {
navigating = true;
}
});
Expand Down
37 changes: 37 additions & 0 deletions test/unit/render.test.js
Expand Up @@ -251,6 +251,43 @@ describe('render', function() {
</h6>`
);
});

it('ignore', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile(
'## h2 tag <!-- {docsify-ignore} -->'
);
expectSameDom(
output,
`
<h2 id="h2-tag">
<a href="#/?id=h2-tag" data-id="h2-tag" class="anchor">
<span>h2 tag </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`
);
expectSameDom(
output,
`
<h1 id="h1-tag">
<a href="#/?id=h1-tag" data-id="h1-tag" class="anchor">
<span>h1 tag </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

0 comments on commit c685754

Please sign in to comment.