X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fhtmlwriter%2Fplugin.js;h=32acfb08bced8f3d6cc26964068ba5c74f23758c;hb=2f22c0c38f17e75be5541089076885442aaa2377;hp=c0dea03893db3a6b373fac9cb35b52853643bb3a;hpb=ea7e3453c7b0f023b050aca6d9f83ab372860d91;p=ckeditor.git diff --git a/_source/plugins/htmlwriter/plugin.js b/_source/plugins/htmlwriter/plugin.js index c0dea03..32acfb0 100644 --- a/_source/plugins/htmlwriter/plugin.js +++ b/_source/plugins/htmlwriter/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -57,36 +57,52 @@ CKEDITOR.htmlWriter = CKEDITOR.tools.createClass( */ this.lineBreakChars = '\n'; - this.forceSimpleAmpersand = false; + this.forceSimpleAmpersand = 0; - this.sortAttributes = true; + this.sortAttributes = 1; - this._.indent = false; + this._.indent = 0; this._.indentation = ''; + // Indicate preformatted block context status. (#5789) + this._.inPre = 0; this._.rules = {}; var dtd = CKEDITOR.dtd; - for ( var e in CKEDITOR.tools.extend( {}, dtd.$block, dtd.$listItem, dtd.$tableContent ) ) + for ( var e in CKEDITOR.tools.extend( {}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) ) { this.setRules( e, { - indent : true, - breakBeforeOpen : true, - breakAfterOpen : true, + indent : 1, + breakBeforeOpen : 1, + breakAfterOpen : 1, breakBeforeClose : !dtd[ e ][ '#' ], - breakAfterClose : true + breakAfterClose : 1 }); } + this.setRules( 'br', { - breakAfterOpen : true + breakAfterOpen : 1 + }); + + this.setRules( 'title', + { + indent : 0, + breakAfterOpen : 0 }); + + this.setRules( 'style', + { + indent : 0, + breakBeforeClose : 1 + }); + // Disable indentation on
.
 		this.setRules( 'pre',
-		{
-		  indent: false
-		} );
+			{
+			  indent : 0
+			});
 	},
 
 	proto :
@@ -144,6 +160,7 @@ CKEDITOR.htmlWriter = CKEDITOR.tools.createClass(
 
 			if ( rules && rules.breakAfterOpen )
 				this.lineBreak();
+			tagName == 'pre' && ( this._.inPre = 1 );
 		},
 
 		/**
@@ -157,8 +174,13 @@ CKEDITOR.htmlWriter = CKEDITOR.tools.createClass(
 		 */
 		attribute : function( attName, attValue )
 		{
-			if ( this.forceSimpleAmpersand )
-				attValue = attValue.replace( /&/, '&' );
+
+			if ( typeof attValue == 'string' )
+			{
+				this.forceSimpleAmpersand && ( attValue = attValue.replace( /&/g, '&' ) );
+				// Browsers don't always escape special character in attribute values. (#4683, #4719).
+				attValue = CKEDITOR.tools.htmlEncodeAttr( attValue );
+			}
 
 			this._.output.push( ' ', attName, '="', attValue, '"' );
 		},
@@ -187,6 +209,7 @@ CKEDITOR.htmlWriter = CKEDITOR.tools.createClass(
 			}
 
 			this._.output.push( '' );
+			tagName == 'pre' && ( this._.inPre = 0 );
 
 			if ( rules && rules.breakAfterClose )
 				this.lineBreak();
@@ -204,7 +227,7 @@ CKEDITOR.htmlWriter = CKEDITOR.tools.createClass(
 			if ( this._.indent )
 			{
 				this.indentation();
-				text = CKEDITOR.tools.ltrim( text );
+				!this._.inPre  && ( text = CKEDITOR.tools.ltrim( text ) );
 			}
 
 			this._.output.push( text );
@@ -233,9 +256,9 @@ CKEDITOR.htmlWriter = CKEDITOR.tools.createClass(
 		 */
 		lineBreak : function()
 		{
-			if ( this._.output.length > 0 )
+			if ( !this._.inPre && this._.output.length > 0 )
 				this._.output.push( this.lineBreakChars );
-			this._.indent = true;
+			this._.indent = 1;
 		},
 
 		/**
@@ -248,8 +271,9 @@ CKEDITOR.htmlWriter = CKEDITOR.tools.createClass(
 		 */
 		indentation : function()
 		{
-			this._.output.push( this._.indentation );
-			this._.indent = false;
+			if( !this._.inPre )
+				this._.output.push( this._.indentation );
+			this._.indent = 0;
 		},
 
 		/**
@@ -262,7 +286,8 @@ CKEDITOR.htmlWriter = CKEDITOR.tools.createClass(
 		 *	
  • breakAfterClose: break line after the closer tag for this element.
  • * * - * All rules default to "false". + * All rules default to "false". Each call to the function overrides + * already present rules, leaving the undefined untouched. * * By default, all elements available in the {@link CKEDITOR.dtd.$block), * {@link CKEDITOR.dtd.$listItem} and {@link CKEDITOR.dtd.$tableContent} @@ -283,7 +308,12 @@ CKEDITOR.htmlWriter = CKEDITOR.tools.createClass( */ setRules : function( tagName, rules ) { - this._.rules[ tagName ] = rules; + var currentRules = this._.rules[ tagName ]; + + if ( currentRules ) + CKEDITOR.tools.extend( currentRules, rules, true ); + else + this._.rules[ tagName ] = rules; } } });