Ticket #2886: 2886_6.patch
File 2886_6.patch, 7.1 KB (added by , 15 years ago) |
---|
-
_source/plugins/htmldataprocessor/plugin.js
5 5 6 6 (function() 7 7 { 8 // Regex to scan for at the end of blocks, which are actually placeholders. 9 var tailNbspRegex = /^[\t\r\n ]* $/; 10 11 function trimFillers( block, fromSource ) 12 { 13 // If the current node is a block, and if we're converting from source or 14 // we're not in IE then search for and remove any tailing BR node. 15 // 16 // Also, any at the end of blocks are fillers, remove them as well. 17 // (#2886) 18 var children = block.children; 19 var lastChild = children[ children.length - 1 ]; 20 if ( lastChild ) 21 { 22 if ( ( fromSource || !CKEDITOR.env.ie ) && lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br' ) 23 children.pop(); 24 if ( lastChild.type == CKEDITOR.NODE_TEXT && tailNbspRegex.test( lastChild.value ) ) 25 children.pop(); 26 } 27 } 28 29 function blockNeedsExtension( block ) 30 { 31 if ( block.children.length < 1 ) 32 return true; 33 34 var lastChild = block.children[ block.children.length - 1 ]; 35 return lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br'; 36 } 37 38 function extendBlockForDisplay( block ) 39 { 40 trimFillers( block, true ); 41 42 if ( blockNeedsExtension( block ) ) 43 { 44 if ( CKEDITOR.env.ie ) 45 block.children.push( new CKEDITOR.htmlParser.text( '\xa0' ) ); 46 else 47 block.children.push( new CKEDITOR.htmlParser.element( 'br', {} ) ); 48 } 49 } 50 51 function extendBlockForOutput( block ) 52 { 53 trimFillers( block ); 54 55 if ( blockNeedsExtension( block ) ) 56 block.children.push( new CKEDITOR.htmlParser.text( '\xa0' ) ); 57 } 58 59 var dtd = CKEDITOR.dtd; 60 61 // $tableContent is replaced by two select tags because tags like tbody should 62 // not be extended. 63 var blockLikeTags = CKEDITOR.tools.extend( {}, dtd.$block, dtd.$listItem, { td : 1, th : 1 } ); 64 8 65 var defaultDataFilterRules = 9 66 { 10 67 elementNames : … … 18 75 // Event attributes (onXYZ) must not be directly set. They can become 19 76 // active in the editing area (IE|WebKit). 20 77 [ ( /^on/ ), '_cke_pa_on' ] 21 ] 78 ], 79 80 elements : {} 22 81 }; 23 82 83 for ( var i in blockLikeTags ) 84 defaultDataFilterRules.elements[ i ] = extendBlockForDisplay; 85 24 86 /** 25 87 * IE sucks with dynamic 'name' attribute after element is created, '_cke_saved_name' is used instead for this attribute. 26 88 */ … … 102 164 } 103 165 } 104 166 }; 167 168 for ( var i in blockLikeTags ) 169 defaultHtmlFilterRules.elements[ i ] = extendBlockForOutput; 105 170 106 171 if ( CKEDITOR.env.ie ) 107 172 { -
_source/tests/plugins/htmldataprocessor/htmldataprocessor.html
3 3 <head> 4 4 <title>Plugin: htmldataprocessor</title> 5 5 <link rel="stylesheet" type="text/css" href="../../test.css" /> 6 <script type="text/javascript" src="../../../../ckeditor_source.js"></script> 6 <script type="text/javascript" src="../../../../ckeditor_source.js"></script> <!-- %REMOVE_LINE% 7 <script type="text/javascript" src="../../../ckeditor.js"></script> 8 %REMOVE_LINE% --> 7 9 <script type="text/javascript" src="../../test.js"></script> 8 10 <script type="text/javascript"> 9 11 … … 102 104 getDataProcessor().toDataFormat( '<INPUT type="checkbox" UNKNOWN autocomplete=off>' ) ); 103 105 }, 104 106 107 test_toDataFormat_ticket_2886_1 : function() 108 { 109 var editor = CKEDITOR.instances.editor1; 110 var test = this; 111 var isReady = !!editor.dataProcessor; 112 113 if ( !isReady ) 114 { 115 editor.on( 'instanceReady', function() 116 { 117 isReady = true; 118 } ); 119 } 120 121 this.wait( function() 122 { 123 if ( !isReady ) 124 { 125 test.wait( arguments.callee, 100 ); 126 return; 127 } 128 129 assert.areSame( '<p>\n\t </p>\n', 130 editor.dataProcessor.toDataFormat( '<p></p>' ) ); 131 }, 100 ); 132 }, 133 134 test_toDataFormat_ticket_2886_2 : function() 135 { 136 var dataProcessor = CKEDITOR.instances.editor1.dataProcessor; 137 138 var source = '<p>Some text<br><br><br></p>'; 139 if ( CKEDITOR.env.ie ) 140 source = '<p>Some text<br><br></p>'; 141 assert.areSame( '<p>\n\tSome text<br />\n\t<br />\n\t </p>\n', 142 dataProcessor.toDataFormat( source ) ); 143 }, 144 145 test_toDataFormat_ticket_2886_3 : function() 146 { 147 var dataProcessor = CKEDITOR.instances.editor1.dataProcessor; 148 149 assert.areSame( '<p>\n\tSome text<br />\n\t<br />\n\t<br />\n\tSome more text</p>\n', 150 dataProcessor.toDataFormat( '<p>Some text<br><br><br>Some more text</p>' ) ); 151 }, 152 153 test_toDataFormat_ticket_2886_4 : function() 154 { 155 var dataProcessor = CKEDITOR.instances.editor1.dataProcessor; 156 157 assert.areSame( '<p>\n\tSome text<br />\n\t<br />\n\t </p>\n', 158 dataProcessor.toDataFormat( '<p>Some text<br><br> </p>' ) ); 159 }, 160 161 test_toDataFormat_ticket_2886_5 : function() 162 { 163 if ( CKEDITOR.env.ie ) 164 return; 165 166 var dataProcessor = CKEDITOR.instances.editor1.dataProcessor; 167 168 assert.areSame( '<p>\n\t </p>\n', 169 dataProcessor.toDataFormat( '<p><br></p>' ) ); 170 }, 171 172 test_toDataFormat_ticket_2886_6 : function() 173 { 174 var dataProcessor = CKEDITOR.instances.editor1.dataProcessor; 175 176 var source = '<p><br><br></p>'; 177 if ( CKEDITOR.env.ie ) 178 source = '<p><br></p>'; 179 180 assert.areSame( '<p>\n\t<br />\n\t </p>\n', 181 dataProcessor.toDataFormat( source ) ); 182 }, 183 184 test_toHtml_ticket_2886_1 : function() 185 { 186 var dataProcessor = CKEDITOR.instances.editor1.dataProcessor; 187 188 var expected = '<p><br /></p>'; 189 if ( CKEDITOR.env.ie ) 190 expected = '<p>\xa0</p>'; 191 assert.areSame( expected, dataProcessor.toHtml( '<p></p>' ) ); 192 }, 193 194 test_toHtml_ticket_2886_2 : function() 195 { 196 var dataProcessor = CKEDITOR.instances.editor1.dataProcessor; 197 198 var expected = '<p>Some text<br />Some other text</p>'; 199 assert.areSame( expected, dataProcessor.toHtml( '<p>Some text<br>Some other text</p>' ) ); 200 }, 201 202 test_toHtml_ticket_2886_3 : function() 203 { 204 var dataProcessor = CKEDITOR.instances.editor1.dataProcessor; 205 206 var expected = '<p>Some text<br /><br /></p>'; 207 if ( CKEDITOR.env.ie ) 208 expected = '<p>Some text<br />\xa0</p>'; 209 assert.areSame( expected, dataProcessor.toHtml( '<p>Some text<br> </p>' ) ); 210 }, 211 212 test_toHtml_ticket_2886_4 : function() 213 { 214 var dataProcessor = CKEDITOR.instances.editor1.dataProcessor; 215 216 var expected = '<p>Some text</p>'; 217 assert.areSame( expected, dataProcessor.toHtml( '<p>Some text<br></p>' )); 218 }, 219 105 220 name : document.title 106 221 }; 107 222 })() ); … … 115 230 </script> 116 231 </head> 117 232 <body> 233 <textarea id="editor1" class="ckeditor" cols="80" rows="10"></textarea> 118 234 </body> 119 235 </html>