+ // Convert leading and trailing whitespaces into \r
+ html = html.replace( /^[ \t]+|[ \t]+$/g, function( match, offset, s )\r
+ {\r
+ if ( match.length == 1 ) // one space, preserve it\r
+ return ' ';\r
+ else if ( !offset ) // beginning of block\r
+ return CKEDITOR.tools.repeat( ' ', match.length - 1 ) + ' ';\r
+ else // end of block\r
+ return ' ' + CKEDITOR.tools.repeat( ' ', match.length - 1 );\r
+ } );\r
+\r
+ // Convert subsequent whitespaces into \r
+ html = html.replace( /[ \t]{2,}/g, function ( match )\r
+ {\r
+ return CKEDITOR.tools.repeat( ' ', match.length - 1 ) + ' ';\r
+ } );\r
+\r
+ var paragraphTag = mode == CKEDITOR.ENTER_P ? 'p' : 'div';\r
+\r
+ // Two line-breaks create one paragraph.\r
+ if ( !isEnterBrMode )\r
+ {\r
+ html = html.replace( /(\n{2})([\s\S]*?)(?:$|\1)/g,\r
+ function( match, group1, text )\r
+ {\r
+ return '<'+paragraphTag + '>' + text + '</' + paragraphTag + '>';\r
+ });\r
+ }\r