Index: /MediaWiki/trunk/plugins/mediawiki/fckplugin.js
===================================================================
--- /MediaWiki/trunk/plugins/mediawiki/fckplugin.js	(revision 2087)
+++ /MediaWiki/trunk/plugins/mediawiki/fckplugin.js	(revision 2088)
@@ -571,10 +571,15 @@
 								this._inLSpace = false ;
 								var len = stringBuilder.length ;
-								if ( !stringBuilder[len-1].EndsWith("\n") && !stringBuilder[len-1].EndsWith(" ") && !stringBuilder[len-2].EndsWith("\n")) {
-									stringBuilder.push( "\n" ) ;
-									len++;
-								}
-								if (stringBuilder[len-1].EndsWith(" ") && stringBuilder[len-2].EndsWith("\n")) {
-									stringBuilder[len-1] = "";
+								if ( len>1 ) {
+									var tail = stringBuilder[len-2] + stringBuilder[len-1];
+									if ( len>2 ) {
+										tail = stringBuilder[len-3] + tail ;
+									}
+									if (tail.EndsWith("\n ")) {
+										stringBuilder[len-1] = stringBuilder[len-1].replace(/ $/, "");
+									}
+									else if ( !tail.EndsWith("\n") ) {
+										stringBuilder.push( "\n" ) ;
+									}
 								}
 							}
@@ -628,5 +633,11 @@
 				{
 					if ( FCKBrowserInfo.IsIE && this._inLSpace ) {
-						textValue = textValue.replace(/\r/, "\r ") ;
+						textValue = textValue.replace( /\r/g, "\r " ) ;
+						if (textValue.EndsWith( "\r " )) {
+							textValue = textValue.replace( /\r $/, "\r" );
+						}
+					}
+					if ( !FCKBrowserInfo.IsIE && this._inLSpace ) {
+						textValue = textValue.replace( /\n(?! )/g, "\n " ) ;
 					}
 					
@@ -653,5 +664,4 @@
 						textValue = textValue + " " ;
 
-					//1785 - remove extra line
 					if ( !this._inLSpace && !this._inPre && textValue == " " ) {
 						var len = stringBuilder.length;
