feat: add externalLinkTarget, close #149

This commit is contained in:
qingwei.li 2017-05-16 23:09:41 +08:00
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 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, noEmoji: false,
ga: '', ga: '',
mergeNavbar: false, mergeNavbar: false,
formatUpdated: '' formatUpdated: '',
externalLinkTarget: '_blank'
}, window.$docsify) }, window.$docsify)
const script = document.currentScript || const script = document.currentScript ||

View file

@ -11,6 +11,7 @@ import { isFn, merge, cached } from '../util/core'
let markdownCompiler = marked let markdownCompiler = marked
let contentBase = '' let contentBase = ''
let currentPath = '' let currentPath = ''
let linkTarget = '_blank'
let renderer = new marked.Renderer() let renderer = new marked.Renderer()
const cacheTree = {} const cacheTree = {}
let toc = [] let toc = []
@ -32,8 +33,12 @@ export const markdown = cached(text => {
markdown.renderer = renderer markdown.renderer = renderer
markdown.init = function (config = {}, base = window.location.pathname) { markdown.init = function (config = {}, {
base = window.location.pathname,
externalLinkTarget
}) {
contentBase = getBasePath(base) contentBase = getBasePath(base)
linkTarget = externalLinkTarget || linkTarget
if (isFn(config)) { if (isFn(config)) {
markdownCompiler = config(marked, renderer) markdownCompiler = config(marked, renderer)
@ -84,7 +89,7 @@ renderer.link = function (href, title, text) {
if (!/:|(\/{2})/.test(href)) { if (!/:|(\/{2})/.test(href)) {
href = toURL(href, null, currentPath) href = toURL(href, null, currentPath)
} else { } else {
blank = ' target="_blank"' blank = ` target="${linkTarget}"`
} }
if (title) { if (title) {
title = ` title="${title}"` title = ` title="${title}"`

View file

@ -160,7 +160,7 @@ export function initRender (vm) {
const config = vm.config const config = vm.config
// Init markdown compiler // Init markdown compiler
markdown.init(config.markdown, config.basePath) markdown.init(config.markdown, config)
const id = config.el || '#app' const id = config.el || '#app'
const navEl = dom.find('nav') || dom.create('nav') const navEl = dom.find('nav') || dom.create('nav')