function cleanTempElements(doc) {
    var tempElement;
    while (tempElement = doc.querySelector("._wysihtml5-temp")) {
      tempElement.parentNode.removeChild(tempElement);
    }
  }
Undo Manager for wysihtml5
slightly inspired by http://rniwa.com/editing/undomanager.html#the-undomanager-interface