function wrapBlock(matchRules, text, state) {
  const { startOffset, endOffset, focusText } = state;
  const focusedText = focusText.text;
  const change = state.change();
  change.moveOffsetsTo(0);
  let length = 0;
  for (let i = 0, k = matchRules.length; i < k; i++) {
    const result = matchRules[i].exec(focusedText);
    if (result) {
      length = result[0].length;
      change.deleteForward(length);
      break;
    }
  }
  const startPos = Math.max(startOffset + text.length - length, 0);
  const endPos = Math.max(endOffset + text.length - length, 0);
  change.insertText(text).moveOffsetsTo(startPos, endPos).focus();

  return change.state;
}
/**
 * Wrap block
 *
 * @param matchRules - list of regexp
 * @param text - marker of the block
 * @param state - editor state
 */
Wrap block
@param matchRules - list of regexp
@param text - marker of the block
@param state - editor state
Wrap block @param matchRules - list of regexp @param text - marker of the block @param state - editor state
function wrapBlock(matchRules, text, state) {
  const { startOffset, endOffset, focusText } = state;
  const focusedText = focusText.text;
  const change = state.change();
  change.moveOffsetsTo(0);
  let length = 0;
  for (let i = 0, k = matchRules.length; i < k; i++) {
    const result = matchRules[i].exec(focusedText);
    if (result) {
      length = result[0].length;
      change.deleteForward(length);
      break;
    }
  }
  const startPos = Math.max(startOffset + text.length - length, 0);
  const endPos = Math.max(endOffset + text.length - length, 0);
  change.insertText(text).moveOffsetsTo(startPos, endPos).focus();
  return change.state;
}
function wrapBlock ( matchRules , text , state ) { const { startOffset , endOffset , focusText } = state ; const focusedText = focusText . text ; const change = state . change ( ) ; change . moveOffsetsTo ( 0 ) ; let length = 0 ; for ( let i = 0 , k = matchRules . length ; i < k ; i ++ ) { const result = matchRules [ i ] . exec ( focusedText ) ; if ( result ) { length = result [ 0 ] . length ; change . deleteForward ( length ) ; break ; } } const startPos = Math . max ( startOffset + text . length - length , 0 ) ; const endPos = Math . max ( endOffset + text . length - length , 0 ) ; change . insertText ( text ) . moveOffsetsTo ( startPos , endPos ) . focus ( ) ; return change . state ; }
Wrap block
 @param matchRules - list of regexp
 @param text - marker of the block
 @param state - editor state
Wrap block @param matchRules - list of regexp @param text - marker of the block @param state - editor state