function parseNode(node, options) {
        var
          allText = grabAllTextNodes(node, []),
          length = allText.length,
          attrib,
          attrname,
          modified,
          fragment,
          subnode,
          text,
          match,
          i,
          index,
          img,
          rawText,
          iconId,
          src;
        while (length--) {
          modified = false;
          fragment = document.createDocumentFragment();
          subnode = allText[length];
          text = subnode.nodeValue;
          i = 0;
          while ((match = re.exec(text))) {
            index = match.index;
            if (index !== i) {
              fragment.appendChild(
                createText(text.slice(i, index), true)
              );
            }
            rawText = match[0];
            iconId = grabTheRightIcon(rawText);
            i = index + rawText.length;
            src = options.callback(iconId, options);
            if (iconId && src) {
              img = new Image();
              img.onerror = options.onerror;
              img.setAttribute('draggable', 'false');
              attrib = options.attributes(rawText, iconId);
              for (attrname in attrib) {
                if (
                  attrib.hasOwnProperty(attrname) &&
                  // don't allow any handlers to be set + don't allow overrides
                  attrname.indexOf('on') !== 0 &&
                  !img.hasAttribute(attrname)
                ) {
                  img.setAttribute(attrname, attrib[attrname]);
                }
              }
              img.className = options.className;
              img.alt = rawText;
              img.src = src;
              modified = true;
              fragment.appendChild(img);
            }
            if (!img) fragment.appendChild(createText(rawText, false));
            img = null;
          }
          // is there actually anything to replace in here ?
          if (modified) {
            // any text left to be added ?
            if (i < text.length) {
              fragment.appendChild(
                createText(text.slice(i), true)
              );
            }
            // replace the text node only, leave intact
            // anything else surrounding such text
            subnode.parentNode.replaceChild(fragment, subnode);
          }
        }
        return node;
      }
/**
       * DOM version of the same logic / parser:
       *  emojify all found sub-text nodes placing images node instead.
       * @param   Element   generic DOM node with some text in some child node
       * @param   Object    options  containing info about how to parse
        *
        *            .callback   Function  the callback to invoke per each found emoji.
        *            .base       string    the base url, by default twemoji.base
        *            .ext        string    the image extension, by default twemoji.ext
        *            .size       string    the assets size, by default twemoji.size
        *
       * @return  Element same generic node with emoji in place, if any.
       */
DOM version of the same logic / parser:
emojify all found sub-text nodes placing images node instead.
@param   Element   generic DOM node with some text in some child node
@param   Object    options  containing info about how to parse

.callback   Function  the callback to invoke per each found emoji.
.base       string    the base url, by default twemoji.base
.ext        string    the image extension, by default twemoji.ext
.size       string    the assets size, by default twemoji.size

@return  Element same generic node with emoji in place, if any.
DOM version of the same logic / parser : emojify all found sub - text nodes placing images node instead . @param Element generic DOM node with some text in some child node @param Object options containing info about how to parse . callback Function the callback to invoke per each found emoji . . base string the base url by default twemoji . base . ext string the image extension by default twemoji . ext . size string the assets size by default twemoji . size @return Element same generic node with emoji in place if any .
function parseNode(node, options) {
        var
          allText = grabAllTextNodes(node, []),
          length = allText.length,
          attrib,
          attrname,
          modified,
          fragment,
          subnode,
          text,
          match,
          i,
          index,
          img,
          rawText,
          iconId,
          src;
        while (length--) {
          modified = false;
          fragment = document.createDocumentFragment();
          subnode = allText[length];
          text = subnode.nodeValue;
          i = 0;
          while ((match = re.exec(text))) {
            index = match.index;
            if (index !== i) {
              fragment.appendChild(
                createText(text.slice(i, index), true)
              );
            }
            rawText = match[0];
            iconId = grabTheRightIcon(rawText);
            i = index + rawText.length;
            src = options.callback(iconId, options);
            if (iconId && src) {
              img = new Image();
              img.onerror = options.onerror;
              img.setAttribute('draggable', 'false');
              attrib = options.attributes(rawText, iconId);
              for (attrname in attrib) {
                if (
                  attrib.hasOwnProperty(attrname) &&
                  attrname.indexOf('on') !== 0 &&
                  !img.hasAttribute(attrname)
                ) {
                  img.setAttribute(attrname, attrib[attrname]);
                }
              }
              img.className = options.className;
              img.alt = rawText;
              img.src = src;
              modified = true;
              fragment.appendChild(img);
            }
            if (!img) fragment.appendChild(createText(rawText, false));
            img = null;
          }
          if (modified) {
            if (i < text.length) {
              fragment.appendChild(
                createText(text.slice(i), true)
              );
            }
            subnode.parentNode.replaceChild(fragment, subnode);
          }
        }
        return node;
      }
function parseNode ( node , options ) { var allText = grabAllTextNodes ( node , [ ] ) , length = allText . length , attrib , attrname , modified , fragment , subnode , text , match , i , index , img , rawText , iconId , src ; while ( length -- ) { modified = false ; fragment = document . createDocumentFragment ( ) ; subnode = allText [ length ] ; text = subnode . nodeValue ; i = 0 ; while ( ( match = re . exec ( text ) ) ) { index = match . index ; if ( index !== i ) { fragment . appendChild ( createText ( text . slice ( i , index ) , true ) ) ; } rawText = match [ 0 ] ; iconId = grabTheRightIcon ( rawText ) ; i = index + rawText . length ; src = options . callback ( iconId , options ) ; if ( iconId && src ) { img = new Image ( ) ; img . onerror = options . onerror ; img . setAttribute ( 'draggable' , 'false' ) ; attrib = options . attributes ( rawText , iconId ) ; for ( attrname in attrib ) { if ( attrib . hasOwnProperty ( attrname ) && attrname . indexOf ( 'on' ) !== 0 && ! img . hasAttribute ( attrname ) ) { img . setAttribute ( attrname , attrib [ attrname ] ) ; } } img . className = options . className ; img . alt = rawText ; img . src = src ; modified = true ; fragment . appendChild ( img ) ; } if ( ! img ) fragment . appendChild ( createText ( rawText , false ) ) ; img = null ; } if ( modified ) { if ( i < text . length ) { fragment . appendChild ( createText ( text . slice ( i ) , true ) ) ; } subnode . parentNode . replaceChild ( fragment , subnode ) ; } } return node ; }
DOM version of the same logic / parser:
  emojify all found sub-text nodes placing images node instead.
DOM version of the same logic / parser : emojify all found sub - text nodes placing images node instead .
// don't allow any handlers to be set + don't allow overrides // is there actually anything to replace in here ? // any text left to be added ? // replace the text node only, leave intact // anything else surrounding such text