tiptap/packages/extension-underline/index.ts

34 lines
675 B
TypeScript
Raw Normal View History

2020-09-22 05:17:30 +08:00
import { Command, Mark } from '@tiptap/core'
export type UnderlineCommand = () => Command
2020-09-10 17:22:41 +08:00
declare module '@tiptap/core/src/Editor' {
2020-09-22 16:49:38 +08:00
interface Commands {
2020-09-22 05:17:30 +08:00
underline: UnderlineCommand,
2020-09-10 17:22:41 +08:00
}
}
export default new Mark()
.name('underline')
.schema(() => ({
parseDOM: [
{
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
},
],
toDOM: () => ['u', 0],
}))
2020-09-24 06:29:05 +08:00
.commands(({ name }) => ({
2020-09-22 05:17:30 +08:00
underline: () => ({ commands }) => {
return commands.toggleMark(name)
2020-09-10 17:22:41 +08:00
},
}))
.keys(({ editor }) => ({
2020-09-24 06:29:05 +08:00
'Mod-u': () => editor.underline(),
2020-09-10 17:22:41 +08:00
}))
.create()