tiptap/packages/extension-horizontal-rule/index.ts

29 lines
660 B
TypeScript
Raw Normal View History

2020-09-10 18:28:14 +08:00
import { Node, nodeInputRule } from '@tiptap/core'
declare module '@tiptap/core/src/Editor' {
interface Editor {
horizontalRule(): Editor,
}
}
export default new Node()
.name('horizontalRule')
.schema(() => ({
group: 'block',
parseDOM: [{ tag: 'hr' }],
toDOM: () => ['hr'],
}))
2020-09-22 05:17:30 +08:00
// .commands(({ editor, type }) => ({
// horizontalRule: next => () => {
// const { state, view } = editor
// const { dispatch } = view
2020-09-10 18:28:14 +08:00
2020-09-22 05:17:30 +08:00
// dispatch(state.tr.replaceSelectionWith(type.create()))
// next()
// },
// }))
2020-09-10 18:28:14 +08:00
.inputRules(({ type }) => [
nodeInputRule(/^(?:---|___\s|\*\*\*\s)$/, type),
])
.create()