Skip to content

Commit a9be6f2

Browse files
committed
Merge branch 'develop' into feat/vue-options
2 parents 5ec2256 + 8cf9fd8 commit a9be6f2

File tree

8 files changed

+87
-21
lines changed

8 files changed

+87
-21
lines changed

packages/docsify-server-renderer/package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/docsify-server-renderer/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
"test": "echo 'hello'"
1616
},
1717
"dependencies": {
18-
"debug": "^4.1.1",
18+
"debug": "^4.3.0",
1919
"docsify": "^4.11.6",
20-
"dompurify": "^2.0.17",
20+
"dompurify": "^2.1.1",
2121
"node-fetch": "^2.6.0",
2222
"resolve-pathname": "^3.0.0"
2323
}

src/core/render/compiler.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { tree as treeTpl } from './tpl';
55
import { genTree } from './gen-tree';
66
import { slugify } from './slugify';
77
import { emojify } from './emojify';
8-
import { getAndRemoveConfig } from './utils';
8+
import { getAndRemoveConfig, removeAtag } from './utils';
99
import { imageCompiler } from './compiler/image';
1010
import { highlightCodeCompiler } from './compiler/code';
1111
import { paragraphCompiler } from './compiler/paragraph';
@@ -206,29 +206,29 @@ export class Compiler {
206206
*/
207207
origin.heading = renderer.heading = function(text, level) {
208208
let { str, config } = getAndRemoveConfig(text);
209-
const nextToc = { level, title: str };
209+
const nextToc = { level, title: removeAtag(str) };
210210

211211
if (/<!-- {docsify-ignore} -->/g.test(str)) {
212212
str = str.replace('<!-- {docsify-ignore} -->', '');
213-
nextToc.title = str;
213+
nextToc.title = removeAtag(str);
214214
nextToc.ignoreSubHeading = true;
215215
}
216216

217217
if (/{docsify-ignore}/g.test(str)) {
218218
str = str.replace('{docsify-ignore}', '');
219-
nextToc.title = str;
219+
nextToc.title = removeAtag(str);
220220
nextToc.ignoreSubHeading = true;
221221
}
222222

223223
if (/<!-- {docsify-ignore-all} -->/g.test(str)) {
224224
str = str.replace('<!-- {docsify-ignore-all} -->', '');
225-
nextToc.title = str;
225+
nextToc.title = removeAtag(str);
226226
nextToc.ignoreAllSubs = true;
227227
}
228228

229229
if (/{docsify-ignore-all}/g.test(str)) {
230230
str = str.replace('{docsify-ignore-all}', '');
231-
nextToc.title = str;
231+
nextToc.title = removeAtag(str);
232232
nextToc.ignoreAllSubs = true;
233233
}
234234

src/core/render/compiler/headline.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
import { getAndRemoveConfig } from '../utils';
1+
import { getAndRemoveConfig, removeAtag } from '../utils';
22
import { slugify } from './slugify';
33

44
export const headingCompiler = ({ renderer, router, _self }) =>
55
(renderer.code = (text, level) => {
66
let { str, config } = getAndRemoveConfig(text);
7-
const nextToc = { level, title: str };
7+
const nextToc = { level, title: removeAtag(str) };
88

99
if (/<!-- {docsify-ignore} -->/g.test(str)) {
1010
str = str.replace('<!-- {docsify-ignore} -->', '');
11-
nextToc.title = str;
11+
nextToc.title = removeAtag(str);
1212
nextToc.ignoreSubHeading = true;
1313
}
1414

1515
if (/{docsify-ignore}/g.test(str)) {
1616
str = str.replace('{docsify-ignore}', '');
17-
nextToc.title = str;
17+
nextToc.title = removeAtag(str);
1818
nextToc.ignoreSubHeading = true;
1919
}
2020

2121
if (/<!-- {docsify-ignore-all} -->/g.test(str)) {
2222
str = str.replace('<!-- {docsify-ignore-all} -->', '');
23-
nextToc.title = str;
23+
nextToc.title = removeAtag(str);
2424
nextToc.ignoreAllSubs = true;
2525
}
2626

2727
if (/{docsify-ignore-all}/g.test(str)) {
2828
str = str.replace('{docsify-ignore-all}', '');
29-
nextToc.title = str;
29+
nextToc.title = removeAtag(str);
3030
nextToc.ignoreAllSubs = true;
3131
}
3232

src/core/render/utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,13 @@ export function getAndRemoveConfig(str = '') {
3838

3939
return { str, config };
4040
}
41+
42+
/**
43+
* Remove the <a> tag from sidebar when the header with link, details see issue 1069
44+
* @param {string} str The string to deal with.
45+
*
46+
* @return {string} str The string after delete the <a> element.
47+
*/
48+
export function removeAtag(str = '') {
49+
return str.replace(/(<\/?a.*?>)/gi, '');
50+
}

src/plugins/search/search.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ export function init(config, vm) {
226226
namespaceSuffix = matches[0];
227227
}
228228
}
229+
paths.unshift(namespaceSuffix + '/');
230+
} else {
231+
paths.unshift('/');
229232
}
230233

231234
const expireKey = resolveExpireKey(config.namespace) + namespaceSuffix;

test/e2e/search.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const docsifyInit = require('../helpers/docsify-init');
2+
3+
// Suite
4+
// -----------------------------------------------------------------------------
5+
describe('Search Plugin Tests', function() {
6+
// Tests
7+
// ---------------------------------------------------------------------------
8+
test('search readme', async () => {
9+
const docsifyInitConfig = {
10+
markdown: {
11+
homepage: `
12+
# Hello World
13+
14+
This is the homepage.
15+
`,
16+
sidebar: `
17+
- [Home page](/)
18+
- [Test Page](test)
19+
`,
20+
},
21+
routes: {
22+
'/test.md': `
23+
# Test Page
24+
25+
This is a custom route.
26+
`,
27+
},
28+
scriptURLs: ['/lib/plugins/search.min.js'],
29+
};
30+
31+
await docsifyInit(docsifyInitConfig);
32+
await page.fill('input[type=search]', 'hello');
33+
await expect(page).toEqualText('.results-panel h2', 'Hello World');
34+
await page.click('.clear-button');
35+
await page.fill('input[type=search]', 'test');
36+
await expect(page).toEqualText('.results-panel h2', 'Test Page');
37+
});
38+
});

test/unit/render-util.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { removeAtag } = require(`${SRC_PATH}/core/render/utils`);
2+
3+
// Suite
4+
// -----------------------------------------------------------------------------
5+
describe('core/render/utils', () => {
6+
// removeAtag()
7+
// ---------------------------------------------------------------------------
8+
describe('removeAtag()', () => {
9+
test('removeAtag from a link', () => {
10+
const result = removeAtag('<a href="www.example.com">content</a>');
11+
12+
expect(result).toEqual('content');
13+
});
14+
});
15+
});

0 commit comments

Comments
 (0)