+ var selection = this.getSelection(),\r
+ mode = selection.getStartElement().hasAscendant( 'pre', true ) ?\r
+ CKEDITOR.ENTER_BR : this.config.enterMode,\r
+ isEnterBrMode = mode == CKEDITOR.ENTER_BR;\r
+\r
+ var html = CKEDITOR.tools.htmlEncode( text.replace( /\r\n|\r/g, '\n' ) );\r
+\r
+ // 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