mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-21 15:28:09 +08:00
42 lines
713 B
TypeScript
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,
|
|
}
|
|
}
|