Index: fckplugin.js
===================================================================
--- fckplugin.js	(revision 29598)
+++ fckplugin.js	(working copy)
@@ -56,6 +56,7 @@
 {
 	_inPre : false,
 	_inLSpace : false,	
+	_appendSpace : false,
 
 	/*
 	 * Returns a string representing the HTML format of "data". The returned
@@ -190,17 +191,52 @@
 				var basicElement = this._BasicElements[ sNodeName ] ;
 				if ( basicElement )
 				{
+
 					if ( basicElement[0] )
-						stringBuilder.push( basicElement[0] ) ;
+					{
+						var pNode = htmlNode.previousSibling;
 
+						if ( pNode != null && pNode.nodeType == 3 && ( pNode.nodeValue == " " || pNode.nodeValue == "" ) )
+						{
+							pNode = pNode.previousSibling;
+						}
+
+						if ( pNode == null || !pNode.tagName || pNode.tagName.toLowerCase() != sNodeName || pNode.nodeValue == "" )
+						{
+							stringBuilder.push( basicElement[0] );
+						}
+
+					}
+
 					if ( !basicElement[2] )
 						this._AppendChildNodes( htmlNode, stringBuilder ) ;
 
 					if ( basicElement[1] )
-						stringBuilder.push( basicElement[1] ) ;
+					{
+						var nNode = htmlNode.nextSibling;
+
+						if ( nNode != null && nNode.nodeType == 3 && ( nNode.nodeValue == " " || nNode.nodeValue == "" ) )
+						{
+							nNode = nNode.previousSibling;
+						}
+
+						if ( nNode == null || !nNode.tagName || nNode.tagName.toLowerCase() != sNodeName || nNode.nodeValue == "" )
+						{
+							stringBuilder.push( basicElement[1] );
+						}
+
+					}
+
+					if ( this._appendSpace == true )
+					{
+						stringBuilder.push( " " );
+						this._appendSpace = false;
+					}
+
 				}
 				else
 				{
+					this._appendSpace = false;
 					switch ( sNodeName )
 					{
 						case 'ol' :
@@ -498,15 +534,31 @@
 					textValue = FCKTools.HTMLEncode( textValue ) ;
 					textValue = textValue.replace( /\u00A0/g, '&nbsp;' ) ;
 
-					if ( !htmlNode.previousSibling ||
-					( stringBuilder.length > 0 && stringBuilder[ stringBuilder.length - 1 ].EndsWith( '\n' ) ) && !this._inLSpace )
+					if ( textValue != "" && ( !htmlNode.previousSibling ||
+					( stringBuilder.length > 0 && stringBuilder[ stringBuilder.length - 1 ].EndsWith( '\n' ) ) && !this._inLSpace ) )
 					{
-						textValue = textValue.LTrim() ;
+						var newTextValue = textValue.LTrim() ;
+						if ( newTextValue != textValue ) 
+						{
+							var old = stringBuilder[ stringBuilder.length - 1 ];
+							stringBuilder[ stringBuilder.length - 1 ] = " ";
+							stringBuilder.push( old );
+						}
+
+						textValue = newTextValue;
 					}
 
 					if ( !htmlNode.nextSibling && !this._inLSpace )
-						textValue = textValue.RTrim() ;
+					{
+						var newTextValue = textValue.RTrim() ;
+						if ( newTextValue != textValue )
+						{
+							this._appendSpace = true;
+						}
 
+						textValue = newTextValue;
+					}
+
 					textValue = textValue.replace( / {2,}/g, ' ' ) ;
 
 					if ( this._inLSpace && textValue.length == 1 && textValue.charCodeAt(0) == 13 )
@@ -514,7 +566,7 @@
 					
 					if ( this._IsInsideCell )
 						textValue = textValue.replace( /\|/g, '&#124;' ) ;
-	
+
 				}
 				else 
 				{
@@ -692,4 +744,4 @@
 			}
 		}
 	}
-}) ;
\ No newline at end of file
+}) ;
