         @processElementNode(node)
 
   appendBlockForNode: (node) ->
-    if @currentBlockElement?
-      unless @currentBlockElement.contains(node)
-        @appendBlockForAttributes({})
-        delete @currentBlockElement
-
-    if node.nodeType is Node.ELEMENT_NODE
-      if window.getComputedStyle(node).display is "block"
-        switch node.tagName.toLowerCase()
-          when "blockquote"
-            @appendBlockForAttributes(quote: true)
-            @currentBlockElement = node
-          when "pre"
-            @appendBlockForAttributes(code: true)
-            @currentBlockElement = node
+    unless @currentBlockElement?.contains(node)
+      if node.nodeType is Node.ELEMENT_NODE
+        if window.getComputedStyle(node).display is "block"
+          switch node.tagName.toLowerCase()
+            when "blockquote"
+              @appendBlockForAttributes(quote: true)
+              @currentBlockElement = node
+            when "pre"
+              @appendBlockForAttributes(code: true)
+              @currentBlockElement = node
+            when "div"
+              @appendBlockForAttributes()
+              @currentBlockElement = node
 
     unless @blocks.length
       @appendBlockForAttributes({})

    text = Trix.Text.textForStringWithAttributes(string, attributes)
    @appendText(@text.appendText(text))

  appendAttachmentForAttributes: (attributes) ->
    if managedAttachment = @findManagedAttachmentByAttributes(attributes)
      attachment = managedAttachment.attachment
    else
      attachment = new Trix.Attachment

    text = Trix.Text.textForAttachmentWithAttributes(attachment, attributes)
    @appendText(@text.appendText(text))

  appendText: (@text) ->
    index = @blocks.length - 1
    block = @blocks[index]
    @blocks[index] = block.copyWithText(@text)

  findManagedAttachmentByAttributes: (attributes) ->
    return unless @attachments
    {identifier, url} = attributes
    if identifier?
      @attachments.findWhere({identifier})
    else if url?
      @attachments.findWhere({url})

  getDocument: ->
    new Trix.Document @blocks

      when "br"
        unless nodeIsExtraBR(node)
          @appendStringWithAttributes("\n", getAttributes(node))
      when "figure"
        if node.classList.contains("attachment")
          attributes = getMetadata(node)
          textAttributes = getAttributes(node)
          if image = node.querySelector("img")
            textAttributes.width = image.width if image.width?
            textAttributes.height = image.height if image.height?
          @appendAttachmentForAttributes(attributes, textAttributes)
          # We have everything we need so avoid processing inner nodes
          node.innerHTML = ""

