add option to put target for the created link

This commit is contained in:
Димитър Илков 2020-02-28 11:04:20 +02:00 committed by GitHub
parent fb147d45f3
commit 03980a95e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,7 @@ export default class Link extends Mark {
get defaultOptions() {
return {
openOnClick: true,
target: null,
}
}
@ -20,6 +21,9 @@ export default class Link extends Mark {
href: {
default: null,
},
target: {
default: null
},
},
inclusive: false,
parseDOM: [
@ -27,12 +31,14 @@ export default class Link extends Mark {
tag: 'a[href]',
getAttrs: dom => ({
href: dom.getAttribute('href'),
target: dom.getAttribute('target'),
}),
},
],
toDOM: node => ['a', {
...node.attrs,
rel: 'noopener noreferrer nofollow',
target : this.options.target,
}, 0],
}
}
@ -71,7 +77,7 @@ export default class Link extends Mark {
if (attrs.href && event.target instanceof HTMLAnchorElement) {
event.stopPropagation()
window.open(attrs.href)
window.open(attrs.href, attrs.target)
}
},
},