Skip to content

Commit 2d73285

Browse files
committed
feat: add externalLinkTarget, close #149
1 parent d2be5ae commit 2d73285

File tree

6 files changed

+41
-5
lines changed

6 files changed

+41
-5
lines changed

docs/configuration.md

+10
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,13 @@ window.$docsify = {
330330
}
331331
}
332332
```
333+
334+
## external-link-target
335+
336+
Currently it defaults to _blank, would be nice if configurable:
337+
338+
```js
339+
window.$docsify = {
340+
externalLinkTarget: '_self' // default: '_blank'
341+
}
342+
```

docs/de-de/configuration.md

+10
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,13 @@ window.$docsify = {
330330
}
331331
}
332332
```
333+
334+
## external-link-target
335+
336+
Currently it defaults to _blank, would be nice if configurable:
337+
338+
```js
339+
window.$docsify = {
340+
externalLinkTarget: '_self' // default: '_blank'
341+
}
342+
```

docs/zh-cn/configuration.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -339,4 +339,14 @@ window.$docsify = {
339339
return time
340340
}
341341
}
342-
```
342+
```
343+
344+
## external-link-target
345+
346+
Currently it defaults to _blank, would be nice if configurable:
347+
348+
```js
349+
window.$docsify = {
350+
externalLinkTarget: '_self' // default: '_blank'
351+
}
352+
```

src/core/config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const config = merge({
1919
noEmoji: false,
2020
ga: '',
2121
mergeNavbar: false,
22-
formatUpdated: ''
22+
formatUpdated: '',
23+
externalLinkTarget: '_blank'
2324
}, window.$docsify)
2425

2526
const script = document.currentScript ||

src/core/render/compiler.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { isFn, merge, cached } from '../util/core'
1111
let markdownCompiler = marked
1212
let contentBase = ''
1313
let currentPath = ''
14+
let linkTarget = '_blank'
1415
let renderer = new marked.Renderer()
1516
const cacheTree = {}
1617
let toc = []
@@ -32,8 +33,12 @@ export const markdown = cached(text => {
3233

3334
markdown.renderer = renderer
3435

35-
markdown.init = function (config = {}, base = window.location.pathname) {
36+
markdown.init = function (config = {}, {
37+
base = window.location.pathname,
38+
externalLinkTarget
39+
}) {
3640
contentBase = getBasePath(base)
41+
linkTarget = externalLinkTarget || linkTarget
3742

3843
if (isFn(config)) {
3944
markdownCompiler = config(marked, renderer)
@@ -84,7 +89,7 @@ renderer.link = function (href, title, text) {
8489
if (!/:|(\/{2})/.test(href)) {
8590
href = toURL(href, null, currentPath)
8691
} else {
87-
blank = ' target="_blank"'
92+
blank = ` target="${linkTarget}"`
8893
}
8994
if (title) {
9095
title = ` title="${title}"`

src/core/render/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export function initRender (vm) {
160160
const config = vm.config
161161

162162
// Init markdown compiler
163-
markdown.init(config.markdown, config.basePath)
163+
markdown.init(config.markdown, config)
164164

165165
const id = config.el || '#app'
166166
const navEl = dom.find('nav') || dom.create('nav')

0 commit comments

Comments
 (0)