tiptap/packages/extension-underline/index.ts

44 lines
753 B
TypeScript
Raw Normal View History

2020-10-22 18:34:49 +08:00
import { Command, createMark } from '@tiptap/core'
2020-09-22 05:17:30 +08:00
2020-10-23 04:40:40 +08:00
const Underline = createMark({
2020-10-22 18:34:49 +08:00
name: 'underline',
parseHTML() {
return [
2020-09-10 17:22:41 +08:00
{
tag: 'u',
},
{
style: 'text-decoration',
2020-09-24 06:29:05 +08:00
getAttrs: node => (node === 'underline' ? {} : false),
2020-09-10 17:22:41 +08:00
},
2020-10-22 18:34:49 +08:00
]
},
renderHTML({ attributes }) {
return ['u', attributes, 0]
},
addCommands() {
return {
2020-10-23 04:40:40 +08:00
underline: (): Command => ({ commands }) => {
2020-10-22 18:34:49 +08:00
return commands.toggleMark('underline')
},
}
},
addKeyboardShortcuts() {
return {
'Mod-u': () => this.editor.underline(),
}
},
})
2020-10-23 04:40:40 +08:00
export default Underline
declare module '@tiptap/core/src/Editor' {
interface AllExtensions {
Underline: typeof Underline,
}
}