add horizontal rule extension

This commit is contained in:
Philipp Kühn
2020-09-10 12:28:14 +02:00
parent cf3bcf3093
commit 667d735a12
7 changed files with 67 additions and 1 deletions

View File

@@ -0,0 +1,28 @@
import { Node, nodeInputRule } from '@tiptap/core'
declare module '@tiptap/core/src/Editor' {
interface Editor {
horizontalRule(): Editor,
}
}
export default new Node()
.name('horizontalRule')
.schema(() => ({
group: 'block',
parseDOM: [{ tag: 'hr' }],
toDOM: () => ['hr'],
}))
.commands(({ editor, type }) => ({
horizontalRule: next => () => {
const { state, view } = editor
const { dispatch } = view
dispatch(state.tr.replaceSelectionWith(type.create()))
next()
},
}))
.inputRules(({ type }) => [
nodeInputRule(/^(?:---|___\s|\*\*\*\s)$/, type),
])
.create()