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