import { InputRule } from "prosemirror-inputrules" ; import { MarkType } from "prosemirror-model" ; export const markInputRule = ( regexp , markType , attrs ? ) : InputRule => { return new InputRule ( regexp , ( state , match , start , end ) => { const tr = state . tr ; if ( match [ 2 ] ) { const textStart = start + match [ 0 ] . indexOf ( match [ 2 ] ) ; const textEnd = textStart + match [ 2 ] . length ; if ( textEnd < end ) { tr . delete ( textEnd , end ) ; } if ( textStart > start ) { tr . delete ( start , textStart ) ; } end = start + match [ 2 ] . length ; } return tr . addMark ( start , end , markType . create ( attrs ) ) ; } ) ; } ; export default markInputRule ;