code: function sh_mergeTags(originalTags, highlightTags) {
    var numOriginalTags = originalTags.length;
    if (numOriginalTags === 0) {
      return highlightTags;
    }
  
    var numHighlightTags = highlightTags.length;
    if (numHighlightTags === 0) {
      return originalTags;
    }
  
    var result = [];
    var originalIndex = 0;
    var highlightIndex = 0;
  
    while (originalIndex < numOriginalTags && highlightIndex < numHighlightTags) {
      var originalTag = originalTags[originalIndex];
      var highlightTag = highlightTags[highlightIndex];
  
      if (originalTag.pos <= highlightTag.pos) {
        result.push(originalTag);
        originalIndex++;
      }
      else {
        result.push(highlightTag);
        if (highlightTags[highlightIndex + 1].pos <= originalTag.pos) {
          highlightIndex++;
          result.push(highlightTags[highlightIndex]);
          highlightIndex++;
        }
        else {
          // new end tag
          result.push({pos: originalTag.pos});
  
          // new start tag
          highlightTags[highlightIndex] = {node: highlightTag.node.cloneNode(false), pos: originalTag.pos};
        }
      }
    }
  
    while (originalIndex < numOriginalTags) {
      result.push(originalTags[originalIndex]);
      originalIndex++;
    }
  
    while (highlightIndex < numHighlightTags) {
      result.push(highlightTags[highlightIndex]);
      highlightIndex++;
    }
  
    return result;
  }
docs: Merges the original tags from an element with the tags produced by highlighting.
  @param  originalTags  an array containing the original tags
  @param  highlightTags  an array containing the highlighting tags - these must not overlap
  @result  an array containing the merged tags