Files
tiptap/packages/tiptap-extensions/src/marks/Link.js
2018-09-23 08:11:20 +02:00

42 lines
623 B
JavaScript

import { Mark } from 'tiptap'
import { updateMark, removeMark } from 'tiptap-commands'
export default class LinkMark extends Mark {
get name() {
return 'link'
}
get schema() {
return {
attrs: {
href: {
default: null,
},
},
inclusive: false,
parseDOM: [
{
tag: 'a[href]',
getAttrs: dom => ({
href: dom.getAttribute('href'),
}),
},
],
toDOM: node => ['a', {
...node.attrs,
rel: 'noopener noreferrer nofollow',
}, 0],
}
}
command({ type, attrs }) {
if (attrs.href) {
return updateMark(type, attrs)
}
return removeMark(type)
}
}