mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-15 02:59:01 +08:00
add option to put target for the created link
This commit is contained in:
parent
fb147d45f3
commit
03980a95e1
@ -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)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user