Index: _source/core/htmlparser/fragment.js =================================================================== --- _source/core/htmlparser/fragment.js (revision 6458) +++ _source/core/htmlparser/fragment.js (revision ) @@ -37,17 +37,15 @@ (function() { - // Elements which the end tag is marked as optional in the HTML 4.01 DTD - // (expect empty elements). - var optionalClose = {colgroup:1,dd:1,dt:1,li:1,option:1,p:1,td:1,tfoot:1,th:1,thead:1,tr:1}; - // Block-level elements whose internal structure should be respected during // parser fixing. - var nonBreakingBlocks = CKEDITOR.tools.extend( - {table:1,ul:1,ol:1,dl:1}, - CKEDITOR.dtd.table, CKEDITOR.dtd.ul, CKEDITOR.dtd.ol, CKEDITOR.dtd.dl ), - listBlocks = CKEDITOR.dtd.$list, listItems = CKEDITOR.dtd.$listItem; + var nonBreakingBlocks = CKEDITOR.tools.extend( { table:1,ul:1,ol:1,dl:1 }, CKEDITOR.dtd.table, CKEDITOR.dtd.ul, CKEDITOR.dtd.ol, CKEDITOR.dtd.dl ); + var listBlocks = { ol:1, ul:1 }; + + // Dtd of the fragment element, basically it accept anything except for intermediate structure, e.g. orphan
element, spaces should be touched differently. - inPre = false, - returnPoint; + inPre = false; function checkPending( newTagName ) { @@ -114,13 +110,29 @@ currentNode.add( pendingBRs.shift() ); } - function addElement( element, target, enforceCurrent ) + /* + * Beside of simply append specified element to target, it also takes + * care of other dirty lifts like forcing block in body, trimming spaces at + * the block boundaries etc. + * + * Note: This function should NOT change the "currentNode" global unless + * there's a return point node specified on the element. + */ + function addElement( element, target ) { + // Ignore any element that has already been added. + if ( element.previous !== undefined ) + return; + target = target || currentNode || fragment; + // Current element might be mangled by fix body below, + // save it for restore later. + var savedCurrent = currentNode; + // If the target is the fragment and this inline element can't go inside // body (if fixForBody). - if ( fixForBody && !target.type ) + if ( fixForBody && ( !target.type || target.name == 'body' ) ) { var elementName, realElementName; if ( element.attributes @@ -130,19 +142,14 @@ else elementName = element.name; - if ( elementName && elementName in CKEDITOR.dtd.$inline ) + if ( elementName && !( elementName in CKEDITOR.dtd.$body || elementName == 'body' || element.isOrphan ) ) { - var savedCurrent = currentNode; - // Create ain the fragment. currentNode = target; parser.onTagOpen( fixForBody, {} ); // The new target now is the
. target = currentNode; - - if ( enforceCurrent ) - currentNode = savedCurrent; } } @@ -170,6 +177,8 @@ currentNode = element.returnPoint; delete element.returnPoint; } + else + currentNode = savedCurrent; } parser.onTagOpen = function( tagName, attributes, selfClosing ) @@ -201,89 +210,75 @@ return; } + while( 1 ) + { - var currentName = currentNode.name; + var currentName = currentNode.name; - var currentDtd = currentName - && ( CKEDITOR.dtd[ currentName ] - || ( currentNode._.isBlockLike ? CKEDITOR.dtd.div : CKEDITOR.dtd.span ) ); + var currentDtd = currentName ? ( CKEDITOR.dtd[ currentName ] + || ( currentNode._.isBlockLike ? CKEDITOR.dtd.div : CKEDITOR.dtd.span ) ) + : rootDtd; - // If the element cannot be child of the current element. + // If the element cannot be child of the current element. - if ( currentDtd // Fragment could receive any elements. - && !element.isUnknown && !currentNode.isUnknown && !currentDtd[ tagName ] ) + if ( !element.isUnknown && !currentNode.isUnknown && !currentDtd[ tagName ] ) - { + { - - var reApply = false, - addPoint; // New position to start adding nodes. - - // Fixing malformed nested lists by moving it into a previous list item. (#3828) - if ( tagName in listBlocks - && currentName in listBlocks ) - { - var children = currentNode.children, - lastChild = children[ children.length - 1 ]; + // Fixing malformed nested lists by moving it into a previous list item. (#3828) + if ( tagName in listBlocks + && currentName in listBlocks ) + { + var children = currentNode.children, + lastChild = children[ children.length - 1 ]; - // Establish the list item if it's not existed. + // Establish the list item if it's not existed. - if ( !( lastChild && lastChild.name in listItems ) ) + if ( !( lastChild && lastChild.name == 'li' ) ) - addElement( ( lastChild = new CKEDITOR.htmlParser.element( 'li' ) ), currentNode ); + addElement( ( lastChild = new CKEDITOR.htmlParser.element( 'li' ) ), currentNode ); - returnPoint = currentNode, addPoint = lastChild; + currentNode = lastChild; - } + } - // If the element name is the same as the current element name, - // then just close the current one and append the new one to the - // parent. This situation usually happens with
,
td1 | td2 |