X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fcore%2Fhtmlparser%2Ffragment.js;h=ad1c93edb2211aafad75bb83bb5f0d51a3b403cd;hp=6c7686c228eb81ec803292dc597992a9bfabe414;hb=c6e377a02b54abc07129d72b632763c727476a15;hpb=941b0a9ba4e673e292510d80a5a86806994b8ea6 diff --git a/_source/core/htmlparser/fragment.js b/_source/core/htmlparser/fragment.js index 6c7686c..ad1c93e 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()
+		{
+			while ( pendingBRs.length )
+				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,
@@ -239,7 +260,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
@@ -308,9 +329,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 +345,7 @@ CKEDITOR.htmlParser.fragment = function()
 				pendingInline = pendingInline.concat( newPendingInline );
 			}
 
-			if( tagName == 'body' )
+			if ( tagName == 'body' )
 				fixForBody = false;
 		};
 
@@ -336,6 +360,7 @@ CKEDITOR.htmlParser.fragment = function()
 					return;
 			}
 
+			sendPendingBRs();
 			checkPending();
 
 			if ( fixForBody
@@ -366,6 +391,8 @@ CKEDITOR.htmlParser.fragment = function()
 		// Parse it.
 		parser.parse( fragmentHtml );
 
+		sendPendingBRs();
+
 		// Close all pending nodes.
 		while ( currentNode.type )
 		{