mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-02 10:19:03 +08:00
36 lines
735 B
TypeScript
36 lines
735 B
TypeScript
import { Mark } from '@tiptap/core'
|
|
|
|
declare module '@tiptap/core/src/Editor' {
|
|
interface Editor {
|
|
underline(): Editor,
|
|
}
|
|
}
|
|
|
|
export const inputRegex = /(?:^|\s)((?:~)((?:[^~]+))(?:~))$/gm
|
|
export const pasteRegex = /(?:^|\s)((?:~)((?:[^~]+))(?:~))/gm
|
|
|
|
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: next => () => {
|
|
editor.toggleMark(name)
|
|
next()
|
|
},
|
|
}))
|
|
.keys(({ editor }) => ({
|
|
'Mod-u': () => editor.underline()
|
|
}))
|
|
.create()
|