Skip to content

Commit

Permalink
[fix 1069] the sidebar links to another site.
Browse files Browse the repository at this point in the history
  • Loading branch information
Koooooo-7 committed Oct 14, 2020
1 parent 25bc9b7 commit 5ad8c2c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/core/render/compiler.js
Original file line number Diff line number Diff line change
@@ -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 = {};

Expand Down Expand Up @@ -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 (/<!-- {docsify-ignore} -->/g.test(str)) {
str = str.replace('<!-- {docsify-ignore} -->', '');
nextToc.title = str;
nextToc.title = removeAtag(str);
nextToc.ignoreSubHeading = true;
}

Expand All @@ -222,7 +222,7 @@ export class Compiler {

if (/<!-- {docsify-ignore-all} -->/g.test(str)) {
str = str.replace('<!-- {docsify-ignore-all} -->', '');
nextToc.title = str;
nextToc.title = removeAtag(str);
nextToc.ignoreAllSubs = true;
}

Expand Down
10 changes: 10 additions & 0 deletions src/core/render/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,13 @@ export function getAndRemoveConfig(str = '') {

return { str, config };
}

/**
* Remove the <a> 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 <a> element.
*/
export function removeAtag(str = '') {
return str.replace(/(<\/?a.*?>)/gi, '');
}

0 comments on commit 5ad8c2c

Please sign in to comment.