Files
tiptap/packages/extension-horizontal-rule/src/index.ts
Philipp Kühn cb5ca0c084 refactoring
2020-11-10 21:18:22 +01:00

42 lines
702 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' {
interface AllExtensions {
HorizontalRule: typeof HorizontalRule,
}
}