src/client/components/PlainMarkdownInput/slate/transforms.js
function hasEmphasis(mark, state) {
  const { startKey, endKey, startOffset, endOffset, texts } = state;

  if (startKey === endKey) {
    const focusText = texts.get(0).text;
    const textLength = focusText.length;
    if (texts.get(0).charsData) {
      const characters = texts.get(0).charsData.characters;
      // not selection
      if (startOffset === endOffset) {
        // string's edge
        if (startOffset === 0 || startOffset === textLength) {
          return false;
        } else {
          const prevChar = characters.get(startOffset - 1);
          const currChar = characters.get(startOffset);
          const hasPrevMark = hasMarkOnChar(prevChar, mark);
          const hasCurrMark = hasMarkOnChar(currChar, mark);
          // between character's marks
          if (hasPrevMark && hasCurrMark) {
            return true;
            // between pairs of markers
          } else if ((mark === 'bold' || mark === 'strikethrough') &&
            startOffset > 1 && startOffset < textLength - 1) {
            const leftPart = focusText.substr(startOffset - 2, 2);
            const rightPart = focusText.substr(startOffset, 2);
            if (leftPart === rightPart &&
              (mark === 'bold' && (leftPart === '**' || leftPart === '__') ||
                mark === 'strikethrough' && leftPart === '~~')) {
              return true;
            }
            // between italic markers and not bold's edge
          } else if (mark === 'italic' && prevChar.text === currChar.text &&
            (currChar.text === '_' || currChar.text === '*') && !hasPrevMark && !hasCurrMark &&
            (!(hasMarkOnChar(prevChar, 'bold') && hasMarkOnChar(currChar, 'bold')) &&
              (startOffset === 1 || startOffset === focusText.length - 1 ||
                !hasMarkOnChar(characters.get(startOffset - 2), 'bold') &&
                !hasMarkOnChar(characters.get(startOffset + 1), 'bold')))) {
            return true;
          }
        }
        // selection
      } else {
        for (let i = startOffset; i < endOffset; i++) {
          if (!hasMarkOnChar(characters.get(i), mark)) {
            return false;
          }
        }
        return true;
      }
    }
  }

  return false;
}
function hasEmphasis(mark, state) {
  const { startKey, endKey, startOffset, endOffset, texts } = state;

  if (startKey === endKey) {
    const focusText = texts.get(0).text;
    const textLength = focusText.length;
    if (texts.get(0).charsData) {
      const characters = texts.get(0).charsData.characters;
      // not selection
      if (startOffset === endOffset) {
        // string's edge
        if (startOffset === 0 || startOffset === textLength) {
          return false;
        } else {
          const prevChar = characters.get(startOffset - 1);
          const currChar = characters.get(startOffset);
          const hasPrevMark = hasMarkOnChar(prevChar, mark);
          const hasCurrMark = hasMarkOnChar(currChar, mark);
          // between character's marks
          if (hasPrevMark && hasCurrMark) {
            return true;
            // between pairs of markers
          } else if ((mark === 'bold' || mark === 'strikethrough') &&
            startOffset > 1 && startOffset < textLength - 1) {
            const leftPart = focusText.substr(startOffset - 2, 2);
            const rightPart = focusText.substr(startOffset, 2);
            if (leftPart === rightPart &&
              (mark === 'bold' && (leftPart === '**' || leftPart === '__') ||
                mark === 'strikethrough' && leftPart === '~~')) {
              return true;
            }
            // between italic markers and not bold's edge
          } else if (mark === 'italic' && prevChar.text === currChar.text &&
            (currChar.text === '_' || currChar.text === '*') && !hasPrevMark && !hasCurrMark &&
            (!(hasMarkOnChar(prevChar, 'bold') && hasMarkOnChar(currChar, 'bold')) &&
              (startOffset === 1 || startOffset === focusText.length - 1 ||
                !hasMarkOnChar(characters.get(startOffset - 2), 'bold') &&
                !hasMarkOnChar(characters.get(startOffset + 1), 'bold')))) {
            return true;
          }
        }
        // selection
      } else {
        for (let i = startOffset; i < endOffset; i++) {
          if (!hasMarkOnChar(characters.get(i), mark)) {
            return false;
          }
        }
        return true;
      }
    }
  }

  return false;
}
function hasEmphasis ( mark , state ) { const { startKey , endKey , startOffset , endOffset , texts } = state ; if ( startKey === endKey ) { const focusText = texts . get ( 0 ) . text ; const textLength = focusText . length ; if ( texts . get ( 0 ) . charsData ) { const characters = texts . get ( 0 ) . charsData . characters ; // not selection if ( startOffset === endOffset ) { // string's edge if ( startOffset === 0 || startOffset === textLength ) { return false ; } else { const prevChar = characters . get ( startOffset - 1 ) ; const currChar = characters . get ( startOffset ) ; const hasPrevMark = hasMarkOnChar ( prevChar , mark ) ; const hasCurrMark = hasMarkOnChar ( currChar , mark ) ; // between character's marks if ( hasPrevMark && hasCurrMark ) { return true ; // between pairs of markers } else if ( ( mark === 'bold' || mark === 'strikethrough' ) && startOffset > 1 && startOffset < textLength - 1 ) { const leftPart = focusText . substr ( startOffset - 2 , 2 ) ; const rightPart = focusText . substr ( startOffset , 2 ) ; if ( leftPart === rightPart && ( mark === 'bold' && ( leftPart === '**' || leftPart === '__' ) || mark === 'strikethrough' && leftPart === '~~' ) ) { return true ; } // between italic markers and not bold's edge } else if ( mark === 'italic' && prevChar . text === currChar . text && ( currChar . text === '_' || currChar . text === '*' ) && ! hasPrevMark && ! hasCurrMark && ( ! ( hasMarkOnChar ( prevChar , 'bold' ) && hasMarkOnChar ( currChar , 'bold' ) ) && ( startOffset === 1 || startOffset === focusText . length - 1 || ! hasMarkOnChar ( characters . get ( startOffset - 2 ) , 'bold' ) && ! hasMarkOnChar ( characters . get ( startOffset + 1 ) , 'bold' ) ) ) ) { return true ; } } // selection } else { for ( let i = startOffset ; i < endOffset ; i ++ ) { if ( ! hasMarkOnChar ( characters . get ( i ) , mark ) ) { return false ; } } return true ; } } } return false ; }
The text has a wrapper in emphasis

@param mark
@param state
@returns {boolean}
The text has a wrapper in emphasis