mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-03 10:59:01 +08:00
34 lines
678 B
TypeScript
34 lines
678 B
TypeScript
import { Command, Mark } from '@tiptap/core'
|
|
|
|
export type UnderlineCommand = () => Command
|
|
|
|
declare module '@tiptap/core/src/Editor' {
|
|
interface Editor {
|
|
underline: UnderlineCommand,
|
|
}
|
|
}
|
|
|
|
export default new Mark()
|
|
.name('underline')
|
|
.schema(() => ({
|
|
parseDOM: [
|
|
{
|
|
tag: 'u',
|
|
},
|
|
{
|
|
style: 'text-decoration',
|
|
getAttrs: node => node === 'underline' ? {} : false,
|
|
},
|
|
],
|
|
toDOM: () => ['u', 0],
|
|
}))
|
|
.commands(({ editor, name }) => ({
|
|
underline: () => ({ commands }) => {
|
|
return commands.toggleMark(name)
|
|
},
|
|
}))
|
|
.keys(({ editor }) => ({
|
|
'Mod-u': () => editor.underline()
|
|
}))
|
|
.create()
|