packages/idyll-compiler/src/processors/post.js
function seperateTextAndHyperLink(textnode, hyperlinks) {
  let match;
  let hyperLinkIndex = 0;
  let substringIndex = 0;
  let newChildNodes = [];
  while (hyperLinkIndex < hyperlinks.length) {
    let regexURL = new RegExp(hyperlinks[hyperLinkIndex], 'g');
    match = regexURL.exec(textnode.substring(substringIndex));
    if (match) {
      let linkEndIndex = regexURL.lastIndex;
      let linkStartIndex = linkEndIndex - hyperlinks[hyperLinkIndex].length;
      let textNodeValue = textnode.substring(substringIndex, linkStartIndex);
      if (textNodeValue !== '') {
        newChildNodes.push(
          createTextNode(textnode.substring(substringIndex, linkStartIndex))
        );
      }
      let anchorElement = createNode('a', [], [hyperlinks[hyperLinkIndex]]);
      setProperty(anchorElement, 'href', hyperlinks[hyperLinkIndex]);
      newChildNodes.push(anchorElement);
      textnode = textnode.substring(linkEndIndex);
      substringIndex = 0;
    }
    hyperLinkIndex++;
  }
  if (textnode != '') {
    newChildNodes.push(createTextNode(textnode));
  }
  return createNode('span', [], newChildNodes);
}
function seperateTextAndHyperLink(textnode, hyperlinks) {
  let match;
  let hyperLinkIndex = 0;
  let substringIndex = 0;
  let newChildNodes = [];
  while (hyperLinkIndex < hyperlinks.length) {
    let regexURL = new RegExp(hyperlinks[hyperLinkIndex], 'g');
    match = regexURL.exec(textnode.substring(substringIndex));
    if (match) {
      let linkEndIndex = regexURL.lastIndex;
      let linkStartIndex = linkEndIndex - hyperlinks[hyperLinkIndex].length;
      let textNodeValue = textnode.substring(substringIndex, linkStartIndex);
      if (textNodeValue !== '') {
        newChildNodes.push(
          createTextNode(textnode.substring(substringIndex, linkStartIndex))
        );
      }
      let anchorElement = createNode('a', [], [hyperlinks[hyperLinkIndex]]);
      setProperty(anchorElement, 'href', hyperlinks[hyperLinkIndex]);
      newChildNodes.push(anchorElement);
      textnode = textnode.substring(linkEndIndex);
      substringIndex = 0;
    }
    hyperLinkIndex++;
  }
  if (textnode != '') {
    newChildNodes.push(createTextNode(textnode));
  }
  return createNode('span', [], newChildNodes);
}
function seperateTextAndHyperLink ( textnode , hyperlinks ) { let match ; let hyperLinkIndex = 0 ; let substringIndex = 0 ; let newChildNodes = [ ] ; while ( hyperLinkIndex < hyperlinks . length ) { let regexURL = new RegExp ( hyperlinks [ hyperLinkIndex ] , 'g' ) ; match = regexURL . exec ( textnode . substring ( substringIndex ) ) ; if ( match ) { let linkEndIndex = regexURL . lastIndex ; let linkStartIndex = linkEndIndex - hyperlinks [ hyperLinkIndex ] . length ; let textNodeValue = textnode . substring ( substringIndex , linkStartIndex ) ; if ( textNodeValue !== '' ) { newChildNodes . push ( createTextNode ( textnode . substring ( substringIndex , linkStartIndex ) ) ) ; } let anchorElement = createNode ( 'a' , [ ] , [ hyperlinks [ hyperLinkIndex ] ] ) ; setProperty ( anchorElement , 'href' , hyperlinks [ hyperLinkIndex ] ) ; newChildNodes . push ( anchorElement ) ; textnode = textnode . substring ( linkEndIndex ) ; substringIndex = 0 ; } hyperLinkIndex ++ ; } if ( textnode != '' ) { newChildNodes . push ( createTextNode ( textnode ) ) ; } return createNode ( 'span' , [ ] , newChildNodes ) ; }
Helper function that seperates hyperlinks from textnodes
@param {*} textnode
@param {*} hyperlinks  Hyperlink array that has all the hyperlinks occuring in the textnode in order of appearance.
@return a new span element encampassing all the new textnodes and anchor tag.
Helper function that seperates hyperlinks from textnodes