tiptap/packages/extension-horizontal-rule/index.ts
2020-09-22 09:08:08 +02:00

29 lines
625 B
TypeScript

import { Command, Node, nodeInputRule } from '@tiptap/core'
export type HorizontalRuleCommand = () => Command
declare module '@tiptap/core/src/Editor' {
interface Editor {
horizontalRule: HorizontalRuleCommand,
}
}
export default new Node()
.name('horizontalRule')
.schema(() => ({
group: 'block',
parseDOM: [{ tag: 'hr' }],
toDOM: () => ['hr'],
}))
.commands(({ type }) => ({
horizontalRule: () => ({ tr }) => {
tr.replaceSelectionWith(type.create())
return true
},
}))
.inputRules(({ type }) => [
nodeInputRule(/^(?:---|___\s|\*\*\*\s)$/, type),
])
.create()