# All files / composer/utils/draft-js-custom-plugins/link linkStrategy.js

14.29% Statements 1/7
0% Branches 0/2
0% Functions 0/2
16.67% Lines 1/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16

    1x

     import twitterText from 'twitter-text';

    const linkStrategy = (contentBlock, callback) => {
      const text = contentBlock.getText();
      const links = twitterText.extractUrlsWithIndices(text);

      links.forEach((link) => {
        // The link plugin doesn't use entities: only match links that don't have
        // any entities attached
        const isOtherEntity = contentBlock.getEntityAt(link.indices[0]) !== null;
        if (!isOtherEntity) callback(...link.indices);
      });
    };

    export default linkStrategy;