 
   removeHiddenContainer: ->
     @containerElement.parentNode.removeChild(@containerElement)
+
+  sanitizeHTML = (html) ->
+    doc = document.implementation.createHTMLDocument("")
+    doc.documentElement.innerHTML = html
+    {body, head} = doc
+
+    for style in head.querySelectorAll("style")
+      body.appendChild(style)
+
+    nodesToRemove = []
+    walker = walkTree(body)
+
+    while walker.nextNode()
+      node = walker.currentNode
+      switch node.nodeType
+        when Node.ELEMENT_NODE
+          if tagName(node) is "script"
+            nodesToRemove.push(node)
+          else
+            for {name} in [node.attributes...]
+              unless name in allowedAttributes or name.indexOf("data-trix") is 0
+                node.removeAttribute(name)
+        when Node.COMMENT_NODE
+          nodesToRemove.push(node)
+
+    for node in nodesToRemove
+      node.parentNode.removeChild(node)
+
+    body.innerHTML
+
+  nodeFilter = (node) ->
+    if tagName(node) is "style"
+      NodeFilter.FILTER_REJECT
+    else
+      NodeFilter.FILTER_ACCEPT
 
   processNode: (node) ->
     switch node.nodeType

      piece.string = string + piece.string
    else
      text.unshift(pieceForString(string))

  getTextAttributes: (element) ->
    attributes = {}

          unless element.parentNode.firstChild is element
            @appendStringWithAttributes(" | ")

  # Document construction

  appendBlockForAttributesWithElement: (attributes, element) ->
    @blockElements.push(element)
    block = blockForAttributes(attributes)
