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

42 lines
713 B
TypeScript

import { Command, createNode, nodeInputRule } from '@tiptap/core'
const HorizontalRule = createNode({
name: 'horizontalRule',
group: 'block',
parseHTML() {
return [
{ tag: 'hr' },
]
},
renderHTML({ attributes }) {
return ['hr', attributes]
},
addCommands() {
return {
horizontalRule: (): Command => ({ tr }) => {
tr.replaceSelectionWith(this.type.create())
return true
},
}
},
addInputRules() {
return [
nodeInputRule(/^(?:---|___\s|\*\*\*\s)$/, this.type),
]
},
})
export default HorizontalRule
declare module '@tiptap/core/src/Editor' {
interface AllExtensions {
HorizontalRule: typeof HorizontalRule,
}
}