diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index 17e0a8144..3e06ca4b5 100644 --- a/src/core/render/compiler.js +++ b/src/core/render/compiler.js @@ -1,17 +1,17 @@ -import marked from 'marked'; import { isAbsolutePath, getPath, getParentPath } from '../router/util'; import { isFn, merge, cached, isPrimitive } from '../util/core'; import { tree as treeTpl } from './tpl'; import { genTree } from './gen-tree'; import { slugify } from './slugify'; import { emojify } from './emojify'; -import { getAndRemoveConfig } from './utils'; +import { getAndRemoveConfig, removeAtag } from './utils'; import { imageCompiler } from './compiler/image'; import { highlightCodeCompiler } from './compiler/code'; import { paragraphCompiler } from './compiler/paragraph'; import { taskListCompiler } from './compiler/taskList'; import { taskListItemCompiler } from './compiler/taskListItem'; import { linkCompiler } from './compiler/link'; +import marked from 'marked'; const cachedLinks = {}; @@ -206,11 +206,11 @@ export class Compiler { */ origin.heading = renderer.heading = function(text, level) { let { str, config } = getAndRemoveConfig(text); - const nextToc = { level, title: str }; + const nextToc = { level, title: removeAtag(str) }; if (//g.test(str)) { str = str.replace('', ''); - nextToc.title = str; + nextToc.title = removeAtag(str); nextToc.ignoreSubHeading = true; } @@ -222,7 +222,7 @@ export class Compiler { if (//g.test(str)) { str = str.replace('', ''); - nextToc.title = str; + nextToc.title = removeAtag(str); nextToc.ignoreAllSubs = true; } diff --git a/src/core/render/utils.js b/src/core/render/utils.js index 100d595cd..bd892c653 100644 --- a/src/core/render/utils.js +++ b/src/core/render/utils.js @@ -38,3 +38,13 @@ export function getAndRemoveConfig(str = '') { return { str, config }; } + +/** + * Remove the tag from sidebar when the header with link, details see issue 1069 + * @param {string} str The string to deal with. + * + * @return {string} str The string after delete the element. + */ +export function removeAtag(str = '') { + return str.replace(/(<\/?a.*?>)/gi, ''); +}