tiptap/packages/extension-underline/index.ts
2020-10-22 22:40:40 +02:00

44 lines
753 B
TypeScript

import { Command, createMark } from '@tiptap/core'
const Underline = createMark({
name: 'underline',
parseHTML() {
return [
{
tag: 'u',
},
{
style: 'text-decoration',
getAttrs: node => (node === 'underline' ? {} : false),
},
]
},
renderHTML({ attributes }) {
return ['u', attributes, 0]
},
addCommands() {
return {
underline: (): Command => ({ commands }) => {
return commands.toggleMark('underline')
},
}
},
addKeyboardShortcuts() {
return {
'Mod-u': () => this.editor.underline(),
}
},
})
export default Underline
declare module '@tiptap/core/src/Editor' {
interface AllExtensions {
Underline: typeof Underline,
}
}