code: function topLevelNodeBefore(node, top) {
      while (!node.previousSibling && node.parentNode != top)
        node = node.parentNode;
      return topLevelNodeAt(node.previousSibling, top);
    }
docs: Find the top-level node that contains the node before this one.