Index: _source/core/htmlparser/element.js
===================================================================
--- _source/core/htmlparser/element.js (revision 3654)
+++ _source/core/htmlparser/element.js Sat Jun 13 01:10:00 CST 2009
@@ -36,6 +36,7 @@
var dtd = CKEDITOR.dtd,
isBlockLike = !!( dtd.$block[ name ] || dtd.$listItem[ name ] || dtd.$tableContent[ name ] ),
+ isPre = name == 'pre';
isEmpty = !!dtd.$empty[ name ];
this.isEmpty = isEmpty;
@@ -45,6 +46,7 @@
this._ =
{
isBlockLike : isBlockLike,
+ isPre : isPre,
hasInlineStarted : isEmpty || !isBlockLike
};
};
@@ -124,7 +126,13 @@
if ( !( element = filter.onElement( element ) ) )
return;
- if ( element.name == writeName )
+ // Element already get serialized.
+ if ( typeof element == 'string' )
+ {
+ writer.write(element);
+ return;
+ }
+ else if ( element.name == writeName )
break;
writeName = element.name;
Index: _source/core/htmlparser/text.js
===================================================================
--- _source/core/htmlparser/text.js (revision 3172)
+++ _source/core/htmlparser/text.js Sat Jun 13 01:10:00 CST 2009
@@ -19,7 +19,7 @@
* @type String
* @example
*/
- this.value = value.replace( spacesRegex, ' ' );
+ this.value = value;
/** @private */
this._ =
@@ -46,9 +46,8 @@
{
var text = this.value;
- if ( filter && !( text = filter.onText( text ) ) )
+ if ( filter && !( text = filter.onText( text, this ) ) )
return;
-
writer.text( text );
}
};
Index: _source/core/htmlparser/fragment.js
===================================================================
--- _source/core/htmlparser/fragment.js (revision 3642)
+++ _source/core/htmlparser/fragment.js Sat Jun 13 01:09:44 CST 2009
@@ -118,9 +118,9 @@
}
// Rtrim empty spaces on block end boundary. (#3585)
- if ( element._.isBlockLike )
+ if ( element._.isBlockLike
+ && !element._.isPre )
{
-
var length = element.children.length,
lastChild = element.children[ length - 1 ],
text;
Index: _source/core/htmlparser/filter.js
===================================================================
--- _source/core/htmlparser/filter.js (revision 3309)
+++ _source/core/htmlparser/filter.js Sat Jun 13 01:10:00 CST 2009
@@ -57,10 +57,10 @@
return filterName( name, this._.attributeNames );
},
- onText : function( text )
+ onText : function( text , node )
{
var textFilter = this._.text;
- return textFilter ? textFilter.filter( text ) : text;
+ return textFilter ? textFilter.filter( text, node ) : text;
},
onComment : function( commentText )
@@ -87,6 +87,10 @@
if ( ret === false )
return null;
+ // Element might been transformed into text node.
+ if( ret && ret.type == CKEDITOR.NODE_TEXT )
+ return this.onText( ret.value, ret );
+
if ( ret && ret != element )
return this.onElement( ret );
}
@@ -212,7 +216,11 @@
if ( ret === false )
return false;
- if ( isObject && ret != currentEntry )
+ // 1. Stop further filtering if current filter has changed the
+ // element.
+ // 2. Make sure we safely return last filtering result.
+ if ( isObject && ret != currentEntry
+ || i == this.length -1 )
return ret;
}
}
Index: _source/plugins/htmldataprocessor/plugin.js
===================================================================
--- _source/plugins/htmldataprocessor/plugin.js (revision 3665)
+++ _source/plugins/htmldataprocessor/plugin.js Sat Jun 13 01:09:30 CST 2009
@@ -56,6 +56,21 @@
block.add( new CKEDITOR.htmlParser.text( '\xa0' ) );
}
+ /**
+ * Filter function for shrinking consequential spaces into one single white
+ * space in text node.
+ * Note: This behavior is IE's default treatment for all text node within
+ * non-pre, we generalize to all browers to reach consistent result.
+ * @param text
+ */
+ function compressSpaces( text , node )
+ {
+ if ( node.parent.name != 'pre' )
+ return text.replace( /[\t\r\n ]{2,}|[\t\r\n]/g, ' ' );
+ else
+ return text;
+ }
+
var dtd = CKEDITOR.dtd;
// Find out the list of block-like tags that can contain
.
@@ -65,7 +80,9 @@
if ( ! ( 'br' in dtd[i] ) )
delete blockLikeTags[i];
}
-
+ // We just avoid filler in
right now. + // TODO: Support filler for, line break is also occupy line height. + delete blockLikeTags.pre; var defaultDataFilterRules = { elementNames : @@ -82,6 +99,8 @@ ] }; + defaultDataFilterRules.text = compressSpaces; + var defaultDataBlockFilterRules = { elements : {} }; for ( var i in blockLikeTags ) @@ -120,6 +139,19 @@ elements : { + br : function( node ) + { + // Gecko had been replacing all linebreaks into
s, which + // are required to be restored here. + if ( node.parent.name == 'pre' ) + { + var parent = node.parent; + node = new CKEDITOR.htmlParser.text( '\n' ); + node.parent = parent; + } + return node; + }, + embed : function( element ) { var parent = element.parent; @@ -169,6 +201,7 @@ } }; + defaultHtmlFilterRules.text = compressSpaces; var defaultHtmlBlockFilterRules = { elements : {} }; for ( var i in blockLikeTags ) @@ -211,6 +244,11 @@ CKEDITOR.htmlDataProcessor = function() { this.writer = new CKEDITOR.htmlWriter(); + // Disable indentation on. + this.writer.setRules( 'pre', + { + indent: false + } ); this.dataFilter = new CKEDITOR.htmlParser.filter(); this.htmlFilter = new CKEDITOR.htmlParser.filter(); };