shjs/shjs-0.6-src/sh_main.js
function sh_insertTags(tags, text) {
  var doc = document;

  var result = document.createDocumentFragment();
  var tagIndex = 0;
  var numTags = tags.length;
  var textPos = 0;
  var textLength = text.length;
  var currentNode = result;

  // output one tag or text node every iteration
  while (textPos < textLength || tagIndex < numTags) {
    var tag;
    var tagPos;
    if (tagIndex < numTags) {
      tag = tags[tagIndex];
      tagPos = tag.pos;
    }
    else {
      tagPos = textLength;
    }

    if (tagPos <= textPos) {
      // output the tag
      if (tag.node) {
        // start tag
        var newNode = tag.node;
        currentNode.appendChild(newNode);
        currentNode = newNode;
      }
      else {
        // end tag
        currentNode = currentNode.parentNode;
      }
      tagIndex++;
    }
    else {
      // output text
      currentNode.appendChild(doc.createTextNode(text.substring(textPos, tagPos)));
      textPos = tagPos;
    }
  }

  return result;
}
function sh_insertTags(tags, text) {
  var doc = document;

  var result = document.createDocumentFragment();
  var tagIndex = 0;
  var numTags = tags.length;
  var textPos = 0;
  var textLength = text.length;
  var currentNode = result;

  // output one tag or text node every iteration
  while (textPos < textLength || tagIndex < numTags) {
    var tag;
    var tagPos;
    if (tagIndex < numTags) {
      tag = tags[tagIndex];
      tagPos = tag.pos;
    }
    else {
      tagPos = textLength;
    }

    if (tagPos <= textPos) {
      // output the tag
      if (tag.node) {
        // start tag
        var newNode = tag.node;
        currentNode.appendChild(newNode);
        currentNode = newNode;
      }
      else {
        // end tag
        currentNode = currentNode.parentNode;
      }
      tagIndex++;
    }
    else {
      // output text
      currentNode.appendChild(doc.createTextNode(text.substring(textPos, tagPos)));
      textPos = tagPos;
    }
  }

  return result;
}
function sh_insertTags ( tags , text ) { var doc = document ; var result = document . createDocumentFragment ( ) ; var tagIndex = 0 ; var numTags = tags . length ; var textPos = 0 ; var textLength = text . length ; var currentNode = result ; // output one tag or text node every iteration
 while ( textPos < textLength || tagIndex < numTags ) { var tag ; var tagPos ; if ( tagIndex < numTags ) { tag = tags [ tagIndex ] ; tagPos = tag . pos ; } else { tagPos = textLength ; } if ( tagPos <= textPos ) { // output the tag
 if ( tag . node ) { // start tag
 var newNode = tag . node ; currentNode . appendChild ( newNode ) ; currentNode = newNode ; } else { // end tag
 currentNode = currentNode . parentNode ; } tagIndex ++ ; } else { // output text
 currentNode . appendChild ( doc . createTextNode ( text . substring ( textPos , tagPos ) ) ) ; textPos = tagPos ; } } return result ; }
Inserts tags into text.
@param  tags  an array of tag objects
@param  text  a string representing the text
@return  a DOM DocumentFragment representing the resulting HTML
Inserts tags into text .