code: function simplifyDOM(root, atEnd) {
      var doc = root.ownerDocument;
      var result = [];
      var leaving = true;
  
      function simplifyNode(node, top) {
        if (node.nodeType == 3) {
          var text = node.nodeValue = fixSpaces(node.nodeValue.replace(/[\r\u200b]/g, "").replace(/\n/g, " "));
          if (text.length) leaving = false;
          result.push(node);
        }
        else if (isBR(node) && node.childNodes.length == 0) {
          leaving = true;
          result.push(node);
        }
        else {
          forEach(node.childNodes, simplifyNode);
          if (!leaving && newlineElements.hasOwnProperty(node.nodeName.toUpperCase())) {
            leaving = true;
            if (!atEnd || !top)
              result.push(doc.createElement("BR"));
          }
        }
      }
  
      simplifyNode(root, true);
      return result;
    }
docs: Helper function for traverseDOM. Flattens an arbitrary DOM node into an array of textnodes and <br> tags.