Skip to content

Commit 5ad8c2c

Browse files
committed
[fix 1069] the sidebar links to another site.
1 parent 25bc9b7 commit 5ad8c2c

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

Diff for: src/core/render/compiler.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import marked from 'marked';
21
import { isAbsolutePath, getPath, getParentPath } from '../router/util';
32
import { isFn, merge, cached, isPrimitive } from '../util/core';
43
import { tree as treeTpl } from './tpl';
54
import { genTree } from './gen-tree';
65
import { slugify } from './slugify';
76
import { emojify } from './emojify';
8-
import { getAndRemoveConfig } from './utils';
7+
import { getAndRemoveConfig, removeAtag } from './utils';
98
import { imageCompiler } from './compiler/image';
109
import { highlightCodeCompiler } from './compiler/code';
1110
import { paragraphCompiler } from './compiler/paragraph';
1211
import { taskListCompiler } from './compiler/taskList';
1312
import { taskListItemCompiler } from './compiler/taskListItem';
1413
import { linkCompiler } from './compiler/link';
14+
import marked from 'marked';
1515

1616
const cachedLinks = {};
1717

@@ -206,11 +206,11 @@ 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

@@ -222,7 +222,7 @@ export class Compiler {
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

Diff for: 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+
}

0 commit comments

Comments
 (0)