feat: add externalLinkTarget, close #149

This commit is contained in:
qingwei.li 2017-05-16 23:09:41 +08:00
parent d2be5aecf8
commit 2d73285de5
No known key found for this signature in database
GPG Key ID: B6DDC2F7AE80B2F4
6 changed files with 41 additions and 5 deletions

View File

@ -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'
}
```

View File

@ -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'
}
```

View File

@ -339,4 +339,14 @@ window.$docsify = {
return time
}
}
```
```
## external-link-target
Currently it defaults to _blank, would be nice if configurable:
```js
window.$docsify = {
externalLinkTarget: '_self' // default: '_blank'
}
```

View File

@ -19,7 +19,8 @@ const config = merge({
noEmoji: false,
ga: '',
mergeNavbar: false,
formatUpdated: ''
formatUpdated: '',
externalLinkTarget: '_blank'
}, window.$docsify)
const script = document.currentScript ||

View File

@ -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}"`

View File

@ -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')