add horizontal rule extension

This commit is contained in:
Philipp Kühn
2020-09-10 12:28:14 +02:00
parent cf3bcf3093
commit 667d735a12
7 changed files with 67 additions and 1 deletions

View File

@@ -8,6 +8,7 @@ export { default as Node } from './src/Node'
export { default as Mark } from './src/Mark'
export { Extensions } from './src/types'
export { default as nodeInputRule } from './src/inputRules/nodeInputRule'
export { default as markInputRule } from './src/inputRules/markInputRule'
export { default as markPasteRule } from './src/pasteRules/markPasteRule'

View File

@@ -0,0 +1,15 @@
import { InputRule } from 'prosemirror-inputrules'
import { NodeType } from 'prosemirror-model'
export default function (regexp: RegExp, type: NodeType, getAttrs?: Function) {
return new InputRule(regexp, (state, match, start, end) => {
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs
const { tr } = state
if (match[0]) {
tr.replaceWith(start - 1, end, type.create(attrs))
}
return tr
})
}