How to use the idyll-ast.createTextNode function in idyll-ast

To help you get started, we’ve selected a few idyll-ast examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github idyll-lang / idyll / packages / idyll-compiler / src / processors / post.js View on Github external
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); 
}
github idyll-lang / idyll / packages / idyll-compiler / src / processors / post.js View on Github external
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); 
}