mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-25 18:27:49 +08:00
29 lines
627 B
TypeScript
29 lines
627 B
TypeScript
import { Command, Node, nodeInputRule } from '@tiptap/core'
|
|
|
|
export type HorizontalRuleCommand = () => Command
|
|
|
|
declare module '@tiptap/core/src/Editor' {
|
|
interface Commands {
|
|
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()
|