JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.0.1
[ckeditor.git] / _source / core / htmlparser / fragment.js
index 7f6c6df..fd16218 100644 (file)
@@ -45,7 +45,8 @@ CKEDITOR.htmlParser.fragment = function()
        // parser fixing.\r
        var nonBreakingBlocks = CKEDITOR.tools.extend(\r
                        {table:1,ul:1,ol:1,dl:1},\r
-                       CKEDITOR.dtd.table, CKEDITOR.dtd.ul, CKEDITOR.dtd.ol, CKEDITOR.dtd.dl );\r
+                       CKEDITOR.dtd.table, CKEDITOR.dtd.ul, CKEDITOR.dtd.ol, CKEDITOR.dtd.dl ),\r
+               listBlocks = CKEDITOR.dtd.$list, listItems = CKEDITOR.dtd.$listItem;\r
 \r
        /**\r
         * Creates a {@link CKEDITOR.htmlParser.fragment} from an HTML string.\r
@@ -189,13 +190,27 @@ CKEDITOR.htmlParser.fragment = function()
                                if ( !currentName )\r
                                        return;\r
 \r
-                               var reApply = false;\r
+                               var reApply = false,\r
+                                       addPoint;   // New position to start adding nodes.\r
 \r
+                               // Fixing malformed nested lists(#3828).\r
+                               if( tagName in listBlocks\r
+                                       && currentName in listBlocks )\r
+                               {\r
+                                       var children = currentNode.children,\r
+                                               lastChild = children[ children.length - 1 ];\r
+                                       // Move inner list into to previous list item if any.\r
+                                       if( lastChild && lastChild.name in listItems )\r
+                                               returnPoint = currentNode, addPoint = lastChild;\r
+                                       // Move inner list outside in the worst case.\r
+                                       else\r
+                                               addElement( currentNode, currentNode.parent );\r
+                               }\r
                                // If the element name is the same as the current element name,\r
                                // then just close the current one and append the new one to the\r
                                // parent. This situation usually happens with <p>, <li>, <dt> and\r
                                // <dd>, specially in IE. Do not enter in this if block in this case.\r
-                               if ( tagName == currentName )\r
+                               else if ( tagName == currentName )\r
                                {\r
                                        addElement( currentNode, currentNode.parent );\r
                                }\r
@@ -222,9 +237,11 @@ CKEDITOR.htmlParser.fragment = function()
                                        reApply = true;\r
                                }\r
 \r
-                               // In any of the above cases, we'll be adding, or trying to\r
-                               // add it to the parent.\r
-                               currentNode = currentNode.returnPoint || currentNode.parent;\r
+                               if( addPoint )\r
+                                       currentNode = addPoint;\r
+                               // Try adding it to the return point, or the parent element.\r
+                               else\r
+                                       currentNode = currentNode.returnPoint || currentNode.parent;\r
 \r
                                if ( reApply )\r
                                {\r