src/client/components/PlainMarkdownInput/slate/transforms.js
function(accent, state) {
  let text = accent === 'ul' ? '* ' : '1. ';
  if (hasMultiLineSelection(state)) {
    const {
      anchorKey,
      anchorOffset,
      focusKey,
      focusOffset,
      isBackward
    } = state.selection;
    const keys = [];
    let firstBefore, firstAfter, lastBefore, lastAfter;
    for (let i = 0; i < state.texts.size; i++) {
      keys.push(state.texts.get(i).key);
    }

    const lineText = state.texts.get(0).text;
    let pref, itemNum, div;
    if (accent === 'ul') {
      const ulMarker = getUlMarker(lineText);
      if (ulMarker) {
        text = ulMarker;
      } else {
        text = '* ';
      }
    } else {
      ({ pref, itemNum, div } = getOlNum(lineText));
    }

    let change = state.change();
    const keysLength = keys.length;
    const lastNum = keysLength - 1;
    for (let i = 0; i < keysLength; i++) {
      moveSelectionToLine(change, keys[i]); // eslint-disable-line no-use-before-define
      if (i === 0) {
        firstBefore = getTextLength(change);
      } else if (i === lastNum) {
        lastBefore = getTextLength(change);
      }
      if (i === 0 && !hasBlock(MATCH_SINGLE_RULE[accent], change.state) || i > 0) {
        text = accent === 'ul' ? text : `${pref}${itemNum}${div} `;
        change = wrapBlockForChange(MATCH_RULES[accent], text, change);// eslint-disable-line
        if (i === 0) {
          firstAfter = getTextLength(change);
        } else if (i === lastNum) {
          lastAfter = getTextLength(change);
        }
        itemNum++;
        continue;
      }
      if (i === 0) {
        firstAfter = firstBefore;
      } else if (i === lastNum) {
        lastAfter = lastBefore;
      }
      itemNum++;
    }
    change.select({
      anchorKey,
      anchorOffset: anchorOffset - firstBefore + firstAfter,
      focusKey,
      focusOffset: focusOffset - lastBefore + lastAfter,
      isFocused: true,
      isBackward
    });

    return change.state;
  } else {
    return wrapBlock(MATCH_RULES[accent], text, state);
  }
}
function(accent, state) {
  let text = accent === 'ul' ? '* ' : '1. ';
  if (hasMultiLineSelection(state)) {
    const {
      anchorKey,
      anchorOffset,
      focusKey,
      focusOffset,
      isBackward
    } = state.selection;
    const keys = [];
    let firstBefore, firstAfter, lastBefore, lastAfter;
    for (let i = 0; i < state.texts.size; i++) {
      keys.push(state.texts.get(i).key);
    }

    const lineText = state.texts.get(0).text;
    let pref, itemNum, div;
    if (accent === 'ul') {
      const ulMarker = getUlMarker(lineText);
      if (ulMarker) {
        text = ulMarker;
      } else {
        text = '* ';
      }
    } else {
      ({ pref, itemNum, div } = getOlNum(lineText));
    }

    let change = state.change();
    const keysLength = keys.length;
    const lastNum = keysLength - 1;
    for (let i = 0; i < keysLength; i++) {
      moveSelectionToLine(change, keys[i]); // eslint-disable-line no-use-before-define
      if (i === 0) {
        firstBefore = getTextLength(change);
      } else if (i === lastNum) {
        lastBefore = getTextLength(change);
      }
      if (i === 0 && !hasBlock(MATCH_SINGLE_RULE[accent], change.state) || i > 0) {
        text = accent === 'ul' ? text : `${pref}${itemNum}${div} `;
        change = wrapBlockForChange(MATCH_RULES[accent], text, change);// eslint-disable-line
        if (i === 0) {
          firstAfter = getTextLength(change);
        } else if (i === lastNum) {
          lastAfter = getTextLength(change);
        }
        itemNum++;
        continue;
      }
      if (i === 0) {
        firstAfter = firstBefore;
      } else if (i === lastNum) {
        lastAfter = lastBefore;
      }
      itemNum++;
    }
    change.select({
      anchorKey,
      anchorOffset: anchorOffset - firstBefore + firstAfter,
      focusKey,
      focusOffset: focusOffset - lastBefore + lastAfter,
      isFocused: true,
      isBackward
    });

    return change.state;
  } else {
    return wrapBlock(MATCH_RULES[accent], text, state);
  }
}
function ( accent , state ) { let text = accent === 'ul' ? '* ' : '1. ' ; if ( hasMultiLineSelection ( state ) ) { const { anchorKey , anchorOffset , focusKey , focusOffset , isBackward } = state . selection ; const keys = [ ] ; let firstBefore , firstAfter , lastBefore , lastAfter ; for ( let i = 0 ; i < state . texts . size ; i ++ ) { keys . push ( state . texts . get ( i ) . key ) ; } const lineText = state . texts . get ( 0 ) . text ; let pref , itemNum , div ; if ( accent === 'ul' ) { const ulMarker = getUlMarker ( lineText ) ; if ( ulMarker ) { text = ulMarker ; } else { text = '* ' ; } } else { ( { pref , itemNum , div } = getOlNum ( lineText ) ) ; } let change = state . change ( ) ; const keysLength = keys . length ; const lastNum = keysLength - 1 ; for ( let i = 0 ; i < keysLength ; i ++ ) { moveSelectionToLine ( change , keys [ i ] ) ; // eslint-disable-line no-use-before-define if ( i === 0 ) { firstBefore = getTextLength ( change ) ; } else if ( i === lastNum ) { lastBefore = getTextLength ( change ) ; } if ( i === 0 && ! hasBlock ( MATCH_SINGLE_RULE [ accent ] , change . state ) || i > 0 ) { text = accent === 'ul' ? text : ` ${ pref } ${ itemNum } ${ div } ` ; change = wrapBlockForChange ( MATCH_RULES [ accent ] , text , change ) ; // eslint-disable-line if ( i === 0 ) { firstAfter = getTextLength ( change ) ; } else if ( i === lastNum ) { lastAfter = getTextLength ( change ) ; } itemNum ++ ; continue ; } if ( i === 0 ) { firstAfter = firstBefore ; } else if ( i === lastNum ) { lastAfter = lastBefore ; } itemNum ++ ; } change . select ( { anchorKey , anchorOffset : anchorOffset - firstBefore + firstAfter , focusKey , focusOffset : focusOffset - lastBefore + lastAfter , isFocused : true , isBackward } ) ; return change . state ; } else { return wrapBlock ( MATCH_RULES [ accent ] , text , state ) ; } }
Wrap text with list token

@param {string} accent
@param state - editor state
@returns {Object} - state
Wrap text with list token