# All files / composer/utils/draft-js-custom-plugins/hashtag hashtagStrategy.js

27.27% Statements 3/11
0% Branches 0/4
0% Functions 0/2
30% Lines 3/10

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    257x

    7x

    7x

     const HASHTAG_REGEX = /(\s|^)#[\w]*/g;

    const findWithRegex = (regex, contentBlock, callback) => {
      const text = contentBlock.getText();
      let matchArr;
      let start;

      while ((matchArr = regex.exec(text)) !== null) { // eslint-disable-line
        const isPaddedBySpace = matchArr[1].length > 0;
        start = matchArr.index + (isPaddedBySpace ? 1 : 0);

        // The hashtag plugin doesn't use entities: only match hashtags that don't
        // have any entities attached
        const isOtherEntity = contentBlock.getEntityAt(start) !== null;
        if (!isOtherEntity) callback(start, matchArr.index + matchArr[0].length);
      }
    };

    const hashtagStrategy = (contentBlock, callback) => {
      findWithRegex(HASHTAG_REGEX, contentBlock, callback);
    };

    export default hashtagStrategy;
    export { HASHTAG_REGEX };