Skip to content

Commit 3c097f5

Browse files
authored
Merge branch 'develop' into fix-search-2
2 parents 54b5344 + c9d4f7a commit 3c097f5

File tree

4 files changed

+37
-12
lines changed

4 files changed

+37
-12
lines changed

src/core/render/compiler.js

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

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

+10
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+
}

test/unit/render-util.test.js

+15
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)