JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.1.1
[ckeditor.git] / _source / core / htmlparser / fragment.js
index 6c7686c..ad1c93e 100644 (file)
@@ -64,6 +64,7 @@ CKEDITOR.htmlParser.fragment = function()
                        html = [],\r
                        fragment = new CKEDITOR.htmlParser.fragment(),\r
                        pendingInline = [],\r
+                       pendingBRs = [],\r
                        currentNode = fragment,\r
                    // Indicate we're inside a <pre> element, spaces should be touched differently.\r
                        inPre = false,\r
@@ -71,6 +72,8 @@ CKEDITOR.htmlParser.fragment = function()
 \r
                function checkPending( newTagName )\r
                {\r
+                       var pendingBRsSent;\r
+\r
                        if ( pendingInline.length > 0 )\r
                        {\r
                                for ( var i = 0 ; i < pendingInline.length ; i++ )\r
@@ -82,6 +85,12 @@ CKEDITOR.htmlParser.fragment = function()
 \r
                                        if ( ( !currentDtd || currentDtd[ pendingName ] ) && ( !newTagName || !pendingDtd || pendingDtd[ newTagName ] || !CKEDITOR.dtd[ newTagName ] ) )\r
                                        {\r
+                                               if ( !pendingBRsSent )\r
+                                               {\r
+                                                       sendPendingBRs();\r
+                                                       pendingBRsSent = 1;\r
+                                               }\r
+\r
                                                // Get a clone for the pending element.\r
                                                pendingElement = pendingElement.clone();\r
 \r
@@ -99,6 +108,12 @@ CKEDITOR.htmlParser.fragment = function()
                        }\r
                }\r
 \r
+               function sendPendingBRs()\r
+               {\r
+                       while ( pendingBRs.length )\r
+                               currentNode.add( pendingBRs.shift() );\r
+               }\r
+\r
                function addElement( element, target, enforceCurrent )\r
                {\r
                        target = target || currentNode || fragment;\r
@@ -181,6 +196,12 @@ CKEDITOR.htmlParser.fragment = function()
                                return;\r
                        }\r
 \r
+                       if ( tagName == 'br' )\r
+                       {\r
+                               pendingBRs.push( element );\r
+                               return;\r
+                       }\r
+\r
                        var currentName = currentNode.name;\r
 \r
                        var currentDtd = currentName\r
@@ -196,7 +217,7 @@ CKEDITOR.htmlParser.fragment = function()
                                        addPoint;   // New position to start adding nodes.\r
 \r
                                // Fixing malformed nested lists by moving it into a previous list item. (#3828)\r
-                               if( tagName in listBlocks\r
+                               if ( tagName in listBlocks\r
                                        && currentName in listBlocks )\r
                                {\r
                                        var children = currentNode.children,\r
@@ -239,7 +260,7 @@ CKEDITOR.htmlParser.fragment = function()
                                        reApply = true;\r
                                }\r
 \r
-                               if( addPoint )\r
+                               if ( addPoint )\r
                                        currentNode = addPoint;\r
                                // Try adding it to the return point, or the parent element.\r
                                else\r
@@ -308,9 +329,12 @@ CKEDITOR.htmlParser.fragment = function()
 \r
                                currentNode = candidate;\r
 \r
-                               if( currentNode.name == 'pre' )\r
+                               if ( currentNode.name == 'pre' )\r
                                        inPre = false;\r
 \r
+                               if ( candidate._.isBlockLike )\r
+                                       sendPendingBRs();\r
+\r
                                addElement( candidate, candidate.parent );\r
 \r
                                // The parent should start receiving new nodes now, except if\r
@@ -321,7 +345,7 @@ CKEDITOR.htmlParser.fragment = function()
                                pendingInline = pendingInline.concat( newPendingInline );\r
                        }\r
 \r
-                       if( tagName == 'body' )\r
+                       if ( tagName == 'body' )\r
                                fixForBody = false;\r
                };\r
 \r
@@ -336,6 +360,7 @@ CKEDITOR.htmlParser.fragment = function()
                                        return;\r
                        }\r
 \r
+                       sendPendingBRs();\r
                        checkPending();\r
 \r
                        if ( fixForBody\r
@@ -366,6 +391,8 @@ CKEDITOR.htmlParser.fragment = function()
                // Parse it.\r
                parser.parse( fragmentHtml );\r
 \r
+               sendPendingBRs();\r
+\r
                // Close all pending nodes.\r
                while ( currentNode.type )\r
                {\r