add underline extension

This commit is contained in:
Philipp Kühn
2020-09-10 11:22:41 +02:00
parent 626301d1f4
commit 5c7e70ba82
2 changed files with 52 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
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()