Index: core/htmlparser/fragment.js
===================================================================
--- core/htmlparser/fragment.js (revision 3504)
+++ core/htmlparser/fragment.js (working copy)
@@ -75,9 +75,18 @@
pendingName = pendingElement.name,
pendingDtd = CKEDITOR.dtd[ pendingName ],
currentDtd = currentNode.name && CKEDITOR.dtd[ currentNode.name ];
-
- if ( ( !currentDtd || currentDtd[ pendingName ] ) && ( !newTagName || !pendingDtd || pendingDtd[ newTagName ] || !CKEDITOR.dtd[ newTagName ] ) )
+ // Check for any pending text nodes.
+ if ( !pendingName )
{
+ // Remove the pending first.
+ pendingInline.splice( i, 1 );
+ i--;
+ if ( fixForBody && !currentNode.type )
+ this.onTagOpen( 'p', {} );
+ currentNode.add( pendingElement );
+ }
+ else if ( ( !currentDtd || currentDtd[ pendingName ] ) && ( !newTagName || !pendingDtd || pendingDtd[ newTagName ] || !CKEDITOR.dtd[ newTagName ] ) )
+ {
// Get a clone for the pending element.
pendingElement = pendingElement.clone();
@@ -196,7 +205,7 @@
}
}
- checkPending( tagName );
+ checkPending.call( this, tagName );
element.parent = currentNode;
element.returnPoint = returnPoint;
@@ -210,6 +219,16 @@
parser.onTagClose = function( tagName )
{
+ // Check for the last pending text node, rtrim the node value.
+ var lastPending = pendingInline[ pendingInline.length -1 ];
+ if ( lastPending && !lastPending.name )
+ {
+ var lastTextNode = pendingInline.pop(),
+ textValue = CKEDITOR.tools.rtrim( lastTextNode.value );
+ if ( textValue.length )
+ currentNode.add( new CKEDITOR.htmlParser.text( textValue ) );
+ }
+
var index = 0,
pendingAdd = [],
candidate = currentNode;
@@ -281,12 +300,10 @@
return;
}
- checkPending();
+ checkPending.call( this );
+ // We need remove the tail-spaces, so pending the text for checking later.
+ pendingInline.push( new CKEDITOR.htmlParser.text( text ) );
- if ( fixForBody && !currentNode.type )
- this.onTagOpen( 'p', {} );
-
- currentNode.add( new CKEDITOR.htmlParser.text( text ) );
};
parser.onCDATA = function( cdata )