Open links to external sites in a new window
This commit is contained in:
parent
83748bd484
commit
08ea135211
1 changed files with 9 additions and 1 deletions
|
@ -317,6 +317,9 @@ export default {
|
||||||
return checkboxes[n]
|
return checkboxes[n]
|
||||||
},
|
},
|
||||||
renderPreview() {
|
renderPreview() {
|
||||||
|
const renderer = new marked.Renderer()
|
||||||
|
const linkRenderer = renderer.link
|
||||||
|
|
||||||
let checkboxNum = -1
|
let checkboxNum = -1
|
||||||
marked.use({
|
marked.use({
|
||||||
renderer: {
|
renderer: {
|
||||||
|
@ -340,6 +343,11 @@ export default {
|
||||||
checkboxNum++
|
checkboxNum++
|
||||||
return `<input type="checkbox" data-checkbox-num="${checkboxNum}" ${checked} class="text-checkbox-${this._uid}"/>`
|
return `<input type="checkbox" data-checkbox-num="${checkboxNum}" ${checked} class="text-checkbox-${this._uid}"/>`
|
||||||
},
|
},
|
||||||
|
link: (href, title, text) => {
|
||||||
|
const isLocal = href.startsWith(`${location.protocol}//${location.hostname}`)
|
||||||
|
const html = linkRenderer.call(renderer, href, title, text)
|
||||||
|
return isLocal ? html : html.replace(/^<a /, `<a target="_blank" rel="noreferrer noopener nofollow" `)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
highlight: function (code, language) {
|
highlight: function (code, language) {
|
||||||
const hljs = require('highlight.js')
|
const hljs = require('highlight.js')
|
||||||
|
@ -348,7 +356,7 @@ export default {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
this.preview = DOMPurify.sanitize(marked(this.text))
|
this.preview = DOMPurify.sanitize(marked(this.text), { ADD_ATTR: ['target'] })
|
||||||
|
|
||||||
// Since the render function is synchronous, we can't do async http requests in it.
|
// Since the render function is synchronous, we can't do async http requests in it.
|
||||||
// Therefore, we can't resolve the blob url at (markdown) compile time.
|
// Therefore, we can't resolve the blob url at (markdown) compile time.
|
||||||
|
|
Loading…
Reference in a new issue