                     lastTag = parentTags.removeLast()
                 }
             case .Text:
+                var text = ""
+                if let pre = preWhitespace {
+                    text += pre.entitiesDecoded()
+                    preWhitespace = nil
+                }
+                text += value.entitiesDecoded()
+
                 let tag = Tag()
-                tag.text = value.entitiesDecoded()
+                tag.text = text
                 lastTag.tags.append(tag)
             case .Cdata:
                 let tag = Tag()

                let match = regex.matches(value.lowercaseString)
                doctype.name = match[1]
                lastTag.tags.append(doctype)
            case .TagOpen:
                let newTag = Tag()
                let name = (value as NSString).substringWithRange(NSMakeRange(1, count(value) - 1))
                newTag.name = name

        var lastTag = self
        var lastAttr: String? = nil
        var parentTags = [Tag]()
        var preWhitespace: String? = nil

        var tmp = input as NSString
        tmp = tmp.stringByReplacingOccurrencesOfString("\r\n", withString: "\n")
