         @setAttribs node, @text[node.__location.start...node.__location.end]
       return
 
-    if node.childNodes?
-      for child, i in node.childNodes
-        if i is node.childNodes.length - 1
-          lastPosition = node.__location?.endTag?.start ? lastPosition
-        else
-          lastPosition = node.childNodes[i+1].__location.start ? lastPosition
-        @fixBounds child, lastPosition
-      newList = []
-      for child in node.childNodes
-        if !child.remove
-          newList.push child
-      node.childNodes = newList
-
-    if node.nodeName is '#document' or node.nodeName is '#document-fragment'
-      node.type = 'document'
-      return
-
     node.type = 'blockTag'
 
     node.__indentLocation = {start: node.__location.startTag.end}

      while i < node.childNodes.length
        @cleanTree node.childNodes[i]
        if not node.childNodes[i].__location
          node.childNodes = node.childNodes[0...i].concat(node.childNodes[i].childNodes || []).concat node.childNodes[i+1...]
        else
          i++

  fixBounds: (node, lastPosition) ->

    if not node
      return

    if node.nodeName is '#text'

    if parseContext and parseContext not in ['html', 'head', 'body']
      root = htmlParser.parseFragment @text
      @cleanTree root
      @fixBounds root
    else
      root = htmlParser.parse @text
      @cleanTree root
      @fixBounds root
      if root.childNodes.length is 0
        root = htmlParser.parseFragment @text
        @cleanTree root
        @fixBounds root
    window.root = root
    window.parse5 = htmlParser
    @mark 0, root, 0, null

  mark: (indentDepth, node, depth, bounds, nomark = false) ->

    switch node.type
      when 'document'
        lastChild = null
        for child in node.childNodes
          if lastChild and lastChild.__location.end > child.__location.start then nomark = true else nomark = false
          @mark indentDepth, child, depth + 1, null, nomark
          unless nomark
            lastChild = child

      when 'emptyTag'
        unless nomark
          @htmlBlock node, depth, bounds
          for attrib in node.attributes
            if attrib.end - attrib.start > 1
              @htmlSocket node, depth + 1, null, @genBounds(attrib), ATTRIBUTE_CLASSES

      when 'blockTag'
        unless nomark
          @htmlBlock node, depth, bounds
          for attrib in node.attributes
            @htmlSocket node, depth + 1, null, @genBounds(attrib), ATTRIBUTE_CLASSES
          indentBounds = @makeIndentBounds node
          if indentBounds.start.line isnt indentBounds.end.line or indentBounds.start.column isnt indentBounds.end.column
            depth++
            prefix = @getIndentPrefix(indentBounds, indentDepth, depth)
            indentDepth += prefix.length
            @addIndent
              bounds: indentBounds
              depth: depth
              prefix: prefix
              classes: @getClasses node
            lastChild = null
          else
            unless TAGS[node.nodeName].content is 'optional' or
                (node.nodeName is 'script' and @hasAttribute node, 'src') or
                node.__indentLocation.end is node.__location.end
              @htmlSocket node, depth + 1, null, indentBounds, null, true
        for child in node.childNodes
          if lastChild and lastChild.__location.end > child.__location.start then nomark = true else nomark = false
          @mark indentDepth, child, depth + 1, null, nomark
          unless nomark
            lastChild = child

      when 'text'
        unless nomark
          @htmlBlock node, depth, bounds
          @htmlSocket node, depth + 1, null

      when 'comment'
        unless nomark
          @htmlBlock node, depth, bounds
          node.__location.start += 4
          node.__location.end -= 3
          @htmlSocket node, depth + 1, null

  isComment: (text) ->
    text.match(/<!--.*-->/)
