X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fcore%2Fhtmlparser%2Ffragment.js;h=9db04dd8b0bd8eff3ed3ce966bdb7eb4a547bb0c;hb=039a051ccf3901311661022a30afd60fc38130c9;hp=6c7686c228eb81ec803292dc597992a9bfabe414;hpb=941b0a9ba4e673e292510d80a5a86806994b8ea6;p=ckeditor.git diff --git a/_source/core/htmlparser/fragment.js b/_source/core/htmlparser/fragment.js index 6c7686c..9db04dd 100644 --- a/_source/core/htmlparser/fragment.js +++ b/_source/core/htmlparser/fragment.js @@ -64,6 +64,7 @@ CKEDITOR.htmlParser.fragment = function() html = [], fragment = new CKEDITOR.htmlParser.fragment(), pendingInline = [], + pendingBRs = [], currentNode = fragment, // Indicate we're inside a
element, spaces should be touched differently. inPre = false, @@ -71,6 +72,8 @@ CKEDITOR.htmlParser.fragment = function() function checkPending( newTagName ) { + var pendingBRsSent; + if ( pendingInline.length > 0 ) { for ( var i = 0 ; i < pendingInline.length ; i++ ) @@ -82,6 +85,12 @@ CKEDITOR.htmlParser.fragment = function() if ( ( !currentDtd || currentDtd[ pendingName ] ) && ( !newTagName || !pendingDtd || pendingDtd[ newTagName ] || !CKEDITOR.dtd[ newTagName ] ) ) { + if ( !pendingBRsSent ) + { + sendPendingBRs(); + pendingBRsSent = 1; + } + // Get a clone for the pending element. pendingElement = pendingElement.clone(); @@ -99,6 +108,12 @@ CKEDITOR.htmlParser.fragment = function() } } + function sendPendingBRs( brsToIgnore ) + { + while ( pendingBRs.length - ( brsToIgnore || 0 ) > 0 ) + currentNode.add( pendingBRs.shift() ); + } + function addElement( element, target, enforceCurrent ) { target = target || currentNode || fragment; @@ -181,6 +196,12 @@ CKEDITOR.htmlParser.fragment = function() return; } + if ( tagName == 'br' ) + { + pendingBRs.push( element ); + return; + } + var currentName = currentNode.name; var currentDtd = currentName @@ -196,7 +217,7 @@ CKEDITOR.htmlParser.fragment = function() addPoint; // New position to start adding nodes. // Fixing malformed nested lists by moving it into a previous list item. (#3828) - if( tagName in listBlocks + if ( tagName in listBlocks && currentName in listBlocks ) { var children = currentNode.children, @@ -216,6 +237,12 @@ CKEDITOR.htmlParser.fragment = function() { addElement( currentNode, currentNode.parent ); } + else if ( tagName in CKEDITOR.dtd.$listItem ) + { + parser.onTagOpen( 'ul', {} ); + addPoint = currentNode; + reApply = true; + } else { if ( nonBreakingBlocks[ currentName ] ) @@ -239,7 +266,7 @@ CKEDITOR.htmlParser.fragment = function() reApply = true; } - if( addPoint ) + if ( addPoint ) currentNode = addPoint; // Try adding it to the return point, or the parent element. else @@ -253,6 +280,7 @@ CKEDITOR.htmlParser.fragment = function() } checkPending( tagName ); + sendPendingBRs(); element.parent = currentNode; element.returnPoint = returnPoint; @@ -308,9 +336,12 @@ CKEDITOR.htmlParser.fragment = function() currentNode = candidate; - if( currentNode.name == 'pre' ) + if ( currentNode.name == 'pre' ) inPre = false; + if ( candidate._.isBlockLike ) + sendPendingBRs(); + addElement( candidate, candidate.parent ); // The parent should start receiving new nodes now, except if @@ -321,7 +352,7 @@ CKEDITOR.htmlParser.fragment = function() pendingInline = pendingInline.concat( newPendingInline ); } - if( tagName == 'body' ) + if ( tagName == 'body' ) fixForBody = false; }; @@ -336,6 +367,7 @@ CKEDITOR.htmlParser.fragment = function() return; } + sendPendingBRs(); checkPending(); if ( fixForBody @@ -360,12 +392,16 @@ CKEDITOR.htmlParser.fragment = function() parser.onComment = function( comment ) { + checkPending(); currentNode.add( new CKEDITOR.htmlParser.comment( comment ) ); }; // Parse it. parser.parse( fragmentHtml ); + // Send all pending BRs except one, which we consider a unwanted bogus. (#5293) + sendPendingBRs( !CKEDITOR.env.ie && 1 ); + // Close all pending nodes. while ( currentNode.type ) {