diff --git a/docs/configuration.md b/docs/configuration.md index aef9879bd..985391416 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -330,3 +330,13 @@ window.$docsify = { } } ``` + +## external-link-target + +Currently it defaults to _blank, would be nice if configurable: + +```js +window.$docsify = { + externalLinkTarget: '_self' // default: '_blank' +} +``` diff --git a/docs/de-de/configuration.md b/docs/de-de/configuration.md index 12495290e..1cd539bbc 100644 --- a/docs/de-de/configuration.md +++ b/docs/de-de/configuration.md @@ -330,3 +330,13 @@ window.$docsify = { } } ``` + +## external-link-target + +Currently it defaults to _blank, would be nice if configurable: + +```js +window.$docsify = { + externalLinkTarget: '_self' // default: '_blank' +} +``` diff --git a/docs/zh-cn/configuration.md b/docs/zh-cn/configuration.md index 39388d820..903e31855 100644 --- a/docs/zh-cn/configuration.md +++ b/docs/zh-cn/configuration.md @@ -339,4 +339,14 @@ window.$docsify = { return time } } -``` \ No newline at end of file +``` + +## external-link-target + +Currently it defaults to _blank, would be nice if configurable: + +```js +window.$docsify = { + externalLinkTarget: '_self' // default: '_blank' +} +``` diff --git a/src/core/config.js b/src/core/config.js index ecec037e2..8b03c7df1 100644 --- a/src/core/config.js +++ b/src/core/config.js @@ -19,7 +19,8 @@ const config = merge({ noEmoji: false, ga: '', mergeNavbar: false, - formatUpdated: '' + formatUpdated: '', + externalLinkTarget: '_blank' }, window.$docsify) const script = document.currentScript || diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index 4c7c04522..26ae4a4a7 100644 --- a/src/core/render/compiler.js +++ b/src/core/render/compiler.js @@ -11,6 +11,7 @@ import { isFn, merge, cached } from '../util/core' let markdownCompiler = marked let contentBase = '' let currentPath = '' +let linkTarget = '_blank' let renderer = new marked.Renderer() const cacheTree = {} let toc = [] @@ -32,8 +33,12 @@ export const markdown = cached(text => { markdown.renderer = renderer -markdown.init = function (config = {}, base = window.location.pathname) { +markdown.init = function (config = {}, { + base = window.location.pathname, + externalLinkTarget +}) { contentBase = getBasePath(base) + linkTarget = externalLinkTarget || linkTarget if (isFn(config)) { markdownCompiler = config(marked, renderer) @@ -84,7 +89,7 @@ renderer.link = function (href, title, text) { if (!/:|(\/{2})/.test(href)) { href = toURL(href, null, currentPath) } else { - blank = ' target="_blank"' + blank = ` target="${linkTarget}"` } if (title) { title = ` title="${title}"` diff --git a/src/core/render/index.js b/src/core/render/index.js index 648751b4b..c4bd4201c 100644 --- a/src/core/render/index.js +++ b/src/core/render/index.js @@ -160,7 +160,7 @@ export function initRender (vm) { const config = vm.config // Init markdown compiler - markdown.init(config.markdown, config.basePath) + markdown.init(config.markdown, config) const id = config.el || '#app' const navEl = dom.find('nav') || dom.create('nav')