tiptap/packages/core/src/inputRules/nodeInputRule.ts

16 lines
469 B
TypeScript
Raw Normal View History

2020-09-10 18:28:14 +08:00
import { InputRule } from 'prosemirror-inputrules'
import { NodeType } from 'prosemirror-model'
2020-09-25 19:52:17 +08:00
export default function (regexp: RegExp, type: NodeType, getAttrs?: (match: any) => any): InputRule {
2020-09-10 18:28:14 +08:00
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
})
2020-09-24 06:29:05 +08:00
}