mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-30 13:07:49 +08:00
29 lines
625 B
TypeScript
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()
|