Skip to content

Commit

Permalink
feat: add externalLinkTarget, close #149
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed May 16, 2017
1 parent d2be5ae commit 2d73285
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 5 deletions.
10 changes: 10 additions & 0 deletions docs/configuration.md
Expand Up @@ -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'
}
```
10 changes: 10 additions & 0 deletions docs/de-de/configuration.md
Expand Up @@ -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'
}
```
12 changes: 11 additions & 1 deletion docs/zh-cn/configuration.md
Expand Up @@ -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'
}
```
3 changes: 2 additions & 1 deletion src/core/config.js
Expand Up @@ -19,7 +19,8 @@ const config = merge({
noEmoji: false,
ga: '',
mergeNavbar: false,
formatUpdated: ''
formatUpdated: '',
externalLinkTarget: '_blank'
}, window.$docsify)

const script = document.currentScript ||
Expand Down
9 changes: 7 additions & 2 deletions src/core/render/compiler.js
Expand Up @@ -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 = []
Expand All @@ -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)
Expand Down Expand Up @@ -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}"`
Expand Down
2 changes: 1 addition & 1 deletion src/core/render/index.js
Expand Up @@ -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')
Expand Down

0 comments on commit 2d73285

Please sign in to comment.