Skip to content

Commit

Permalink
Merge pull request #917 from vkallore/develop
Browse files Browse the repository at this point in the history
Fix #914
  • Loading branch information
anikethsaha authored Dec 2, 2019
2 parents 8f496d8 + 11762cb commit 378d7bb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,19 @@ window.$docsify = {
};
```

## externalLinkRel

- type: `String`
- default: `noopener`

Default `'noopener'` (no opener) prevents the newly opened external page (when [externalLinkTarget](#externallinktarget) is `'_blank'`) from having the ability to control our page. No `rel` is set when its not `'_blank'`.

```js
window.$docsify = {
externalLinkTarget: '' // default: 'noopener'
};
```

## routerMode

- type: `String`
Expand Down
1 change: 1 addition & 0 deletions src/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default function () {
externalLinkTarget: '_blank',
// this config for the corner
cornerExternalLinkTarget: '_blank',
externalLinkRel: 'noopener',
routerMode: 'hash',
noCompileLinks: [],
relativePath: false
Expand Down
4 changes: 3 additions & 1 deletion src/core/render/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class Compiler {
this.toc = []
this.cacheTOC = {}
this.linkTarget = config.externalLinkTarget || '_blank'
this.linkRel = this.linkTarget === '_blank' ? (config.externalLinkRel || 'noopener') : ''
this.contentBase = router.getBasePath()

const renderer = this._initRenderer()
Expand Down Expand Up @@ -185,7 +186,7 @@ export class Compiler {

_initRenderer() {
const renderer = new marked.Renderer()
const {linkTarget, router, contentBase} = this
const {linkTarget, linkRel, router, contentBase} = this
const _self = this
const origin = {}

Expand Down Expand Up @@ -243,6 +244,7 @@ export class Compiler {
href = router.toURL(href, null, router.getCurrentPath())
} else {
attrs += href.indexOf('mailto:') === 0 ? '' : ` target="${linkTarget}"`
attrs += href.indexOf('mailto:') === 0 ? '' : (linkRel !== '' ? ` rel="${linkRel}"` : '')
}

if (config.target) {
Expand Down

0 comments on commit 378d7bb

Please sign in to comment.