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