Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c9d4f7a

Browse filesBrowse files
authored
fix: the sidebar links to another site. (docsifyjs#1336)
* fix : the sidebar links to another site
1 parent 25bc9b7 commit c9d4f7a
Copy full SHA for c9d4f7a

4 files changed

+37-12Lines changed: 37 additions & 12 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/core/render/compiler.js‎

Copy file name to clipboardExpand all lines: src/core/render/compiler.js
+6-6Lines 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

Collapse file

‎src/core/render/compiler/headline.js‎

Copy file name to clipboardExpand all lines: src/core/render/compiler/headline.js
+6-6Lines 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

Collapse file

‎src/core/render/utils.js‎

Copy file name to clipboardExpand all lines: src/core/render/utils.js
+10Lines 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+
}
Collapse file

‎test/unit/render-util.test.js‎

Copy file name to clipboard
+15Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.