Ticket #2886: 2886_4.patch
File 2886_4.patch, 7.8 KB (added by , 15 years ago) |
---|
-
_source/plugins/htmldataprocessor/plugin.js
5 5 6 6 (function() 7 7 { 8 function blockNeedsExtension( block ) 9 { 10 if ( block.children.length < 1 ) 11 return true; 12 13 var lastChild = block.children[ block.children.length - 1 ]; 14 return lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br'; 15 } 16 17 function extendBlockForDisplay( block ) 18 { 19 if ( blockNeedsExtension( block ) ) 20 { 21 if ( CKEDITOR.env.ie ) 22 block.children.push( new CKEDITOR.htmlParser.text( '\xa0' ) ); 23 else 24 block.children.push( new CKEDITOR.htmlParser.element( 'br', {} ) ); 25 } 26 } 27 28 function extendBlockForOutput( block ) 29 { 30 if ( blockNeedsExtension( block ) ) 31 block.children.push( new CKEDITOR.htmlParser.text( '\xa0' ) ); 32 } 33 34 var dtd = CKEDITOR.dtd; 35 36 // $tableContent is replaced by two select tags because tags like tbody should 37 // not be extended. 38 var blockLikeTags = CKEDITOR.tools.extend( {}, dtd.$block, dtd.$listItem, { td : 1, th : 1 } ); 39 8 40 var defaultDataFilterRules = 9 41 { 10 42 elementNames : … … 18 50 // Event attributes (onXYZ) must not be directly set. They can become 19 51 // active in the editing area (IE|WebKit). 20 52 [ ( /^on/ ), '_cke_pa_on' ] 21 ] 53 ], 54 55 elements : {} 22 56 }; 23 57 58 for ( var i in blockLikeTags ) 59 defaultDataFilterRules.elements[ i ] = extendBlockForDisplay; 60 24 61 /** 25 62 * IE sucks with dynamic 'name' attribute after element is created, '_cke_saved_name' is used instead for this attribute. 26 63 */ … … 102 139 } 103 140 } 104 141 }; 142 143 for ( var i in blockLikeTags ) 144 defaultHtmlFilterRules.elements[ i ] = extendBlockForOutput; 105 145 106 146 if ( CKEDITOR.env.ie ) 107 147 { -
_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 105 212 name : document.title 106 213 }; 107 214 })() ); … … 115 222 </script> 116 223 </head> 117 224 <body> 225 <textarea id="editor1" class="ckeditor" cols="80" rows="10"></textarea> 118 226 </body> 119 227 </html> -
_source/core/htmlparser/fragment.js
47 47 {table:1,ul:1,ol:1,dl:1}, 48 48 CKEDITOR.dtd.table, CKEDITOR.dtd.ul, CKEDITOR.dtd.ol, CKEDITOR.dtd.dl ); 49 49 50 // Regex to scan for at the end of blocks, which is actually placeholders. 51 var tailNbspRegex = /^[\t\r\n ]* $/; 52 50 53 /** 51 54 * Creates a {@link CKEDITOR.htmlParser.fragment} from an HTML string. 52 55 * @param {String} fragmentHtml The HTML to be parsed, filling the fragment. … … 117 120 currentNode = savedCurrent; 118 121 } 119 122 120 // Rtrim empty spaces on block end boundary. (#3585)121 123 if ( element._.isBlockLike ) 122 124 { 123 124 var length = element.children.length,125 lastChild = element.children[length - 1 ],125 // Rtrim empty spaces on block end boundary. (#3585) 126 var children = element.children, 127 lastChild = children[ children.length - 1 ], 126 128 text; 127 129 if ( lastChild && lastChild.type == CKEDITOR.NODE_TEXT ) 128 130 { 129 131 if ( !( text = CKEDITOR.tools.rtrim( lastChild.value ) ) ) 130 element.children.length = length -1;132 children.pop(); 131 133 else 132 134 lastChild.value = text; 133 135 } 136 137 // If the current node is a block, and the current browser is not IE; then 138 // search for and remove the tailing BR node, if any. (#2862) 139 lastChild = children[ children.length - 1 ]; 140 if ( lastChild ) 141 { 142 if ( !CKEDITOR.env.ie && lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br' ) 143 children.pop(); 144 if ( lastChild.type == CKEDITOR.NODE_TEXT && tailNbspRegex.test( lastChild.value ) ) 145 children.pop(); 146 } 134 147 } 135 148 136 149 target.add( element );