Ticket #2886: 2886_2.patch
File 2886_2.patch, 9.0 KB (added by , 15 years ago) |
---|
-
_source/core/htmlparser/element.js
50 50 /** @private */ 51 51 this._ = 52 52 { 53 isBlockLike : isBlockLike, 54 hasInlineStarted : isEmpty || !isBlockLike 53 isBlockLike : isBlockLike 55 54 }; 56 55 }; 57 56 -
_source/core/htmlparser/fragment.js
30 30 /** @private */ 31 31 this._ = 32 32 { 33 isBlockLike : true, 34 hasInlineStarted : false 33 isBlockLike : true 35 34 }; 36 35 }; 37 36 … … 56 55 html = [], 57 56 fragment = new CKEDITOR.htmlParser.fragment(), 58 57 pendingInline = [], 58 isBrPending, isBrOptional, 59 isPre, 60 hasInlineContent, 59 61 currentNode = fragment; 60 62 61 63 var checkPending = function( newTagName ) 62 64 { 65 if ( isBrPending ) 66 { 67 if ( !newTagName || CKEDITOR.dtd.$empty[ newTagName ] || newTagName == 'br' ) 68 currentNode.add( new CKEDITOR.htmlParser.element( 'br', {} ) ); 69 isBrPending = false; 70 } 71 63 72 if ( pendingInline.length > 0 ) 64 73 { 65 74 for ( var i = 0 ; i < pendingInline.length ; i++ ) … … 74 83 // Get a clone for the pending element. 75 84 pendingElement = pendingElement.clone(); 76 85 86 if ( hasInlineContent ) 87 hasInlineContent = !pendingElement._.isBlockLike && pendingElement.name != 'br'; 88 77 89 // Add it to the current node and make it the current, 78 90 // so the new element will be added inside of it. 79 91 currentNode.add( pendingElement ); … … 90 102 91 103 parser.onTagOpen = function( tagName, attributes, selfClosing ) 92 104 { 105 if ( tagName == 'br' ) 106 { 107 if ( isPre ) 108 { 109 currentNode.add( new CKEDITOR.htmlParser.text( '\n', true ) ); 110 return; 111 } 112 else if ( isBrOptional ) 113 { 114 isBrPending = true; 115 isBrOptional = false; 116 return; 117 } 118 } 119 else if ( tagName == 'pre' ) 120 isPre = true; 121 93 122 var element = new CKEDITOR.htmlParser.element( tagName, attributes ); 94 123 95 124 // "isEmpty" will be always "false" for unknown elements, so we … … 104 133 return; 105 134 } 106 135 136 if ( element.isEmpty ) 137 isBrOptional = true; 138 107 139 var currentName = currentNode.name, 108 140 currentDtd = ( currentName && CKEDITOR.dtd[ currentName ] ) || ( currentNode._.isBlockLike ? CKEDITOR.dtd.div : CKEDITOR.dtd.span ); 109 141 … … 133 165 // and try adding the new one after it. 134 166 pendingInline.unshift( currentNode ); 135 167 } 168 else if ( isBrPending ) 169 isBrPending = !currentNode._.isBlockLike; 136 170 137 171 reApply = true; 138 172 } … … 152 186 153 187 currentNode.add( element ); 154 188 189 if ( hasInlineContent ) 190 hasInlineContent = !element._.isBlockLike && element.name != 'br'; 191 155 192 if ( !element.isEmpty ) 156 193 currentNode = element; 157 194 }; … … 161 198 var closingElement = currentNode, 162 199 index = 0; 163 200 201 if ( tagName == 'pre' ) 202 isPre = false; 203 164 204 while ( closingElement && closingElement.name != tagName ) 165 205 { 166 206 // If this is an inline element, add it to the pending list, so … … 178 218 } 179 219 180 220 if ( closingElement ) 221 { 222 if ( isBrPending ) 223 isBrPending = !closingElement._.isBlockLike; 224 181 225 currentNode = closingElement.parent; 226 } 182 227 else if ( pendingInline.length > index ) 183 228 { 184 229 // If we didn't find any parent to be closed, let's check the … … 199 244 200 245 parser.onText = function( text ) 201 246 { 202 if ( ! currentNode._.hasInlineStarted)247 if ( !hasInlineContent && !isPre ) 203 248 { 204 249 text = CKEDITOR.tools.ltrim( text ); 205 250 … … 208 253 } 209 254 210 255 checkPending(); 211 currentNode.add( new CKEDITOR.htmlParser.text( text ) ); 256 currentNode.add( new CKEDITOR.htmlParser.text( text, isPre ) ); 257 258 isBrOptional = true; 212 259 }; 213 260 214 261 parser.onComment = function( comment ) … … 261 308 node.parent = this; 262 309 263 310 this.children.push( node ); 264 265 this._.hasInlineStarted = node.type == CKEDITOR.NODE_TEXT || ( node.type == CKEDITOR.NODE_ELEMENT && !node._.isBlockLike );266 311 }, 267 312 268 313 /** -
_source/core/htmlparser/text.js
12 12 * @constructor 13 13 * @example 14 14 */ 15 CKEDITOR.htmlParser.text = function( value )15 CKEDITOR.htmlParser.text = function( value, noSpacesFix ) 16 16 { 17 17 /** 18 18 * The text value. 19 19 * @type String 20 20 * @example 21 21 */ 22 this.value = value.replace( spacesRegex, ' ' );22 this.value = noSpacesFix ? value : value.replace( spacesRegex, ' ' ); 23 23 24 24 /** @private */ 25 25 this._ = -
_source/plugins/htmlwriter/plugin.js
53 53 output : [], 54 54 indent : false, 55 55 indentation : '', 56 rules : {} 56 rules : {}, 57 cdata : 0 57 58 }; 58 59 59 60 var dtd = CKEDITOR.dtd; … … 62 63 { 63 64 this.setRules( e, 64 65 { 65 indent : true,66 indent : ( e != 'pre' ), 66 67 breakBeforeOpen : true, 67 68 breakAfterOpen : true, 68 69 breakBeforeClose : !dtd[ e ][ '#' ], … … 101 102 } 102 103 103 104 this._.output.push( '<', tagName ); 105 106 if ( tagName == 'pre' ) 107 this._.cdata++; 104 108 }, 105 109 106 110 /** … … 174 178 175 179 if ( rules && rules.breakAfterClose ) 176 180 this.lineBreak(); 181 182 if ( tagName == 'pre' ) 183 this._.cdata--; 177 184 }, 178 185 179 186 /** … … 185 192 */ 186 193 text : function( text ) 187 194 { 188 if ( this._.indent )195 if ( this._.indent && !this._.cdata ) 189 196 { 190 197 this.indentation(); 191 198 text = CKEDITOR.tools.ltrim( text ); -
_source/tests/plugins/htmldataprocessor/htmldataprocessor.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 3 <head> 4 4 <title>Plugin: htmldataprocessor</title> … … 79 79 assert.areSame( '<x:x><p>Test</p></x:x>', getDataProcessor().toDataFormat( element ) ); 80 80 }, 81 81 82 test_toDataFormat_4 : function() 83 { 84 var element = new CKEDITOR.dom.element.createFromHtml( '<div><p><br></p></div>' ); 85 86 assert.areSame( '<p><br /></p>', getDataProcessor().toDataFormat( element ) ); 87 }, 88 89 test_toDataFormat_5 : function() 90 { 91 var element = new CKEDITOR.dom.element.createFromHtml( '<div><p><br>A</p></div>' ); 92 93 assert.areSame( '<p><br />A</p>', getDataProcessor().toDataFormat( element ) ); 94 }, 95 96 test_toDataFormat_6 : function() 97 { 98 var element = new CKEDITOR.dom.element.createFromHtml( '<div><p>A<br></p></div>' ); 99 100 assert.areSame( '<p>A</p>', getDataProcessor().toDataFormat( element ) ); 101 }, 102 103 test_toDataFormat_7 : function() 104 { 105 var element = new CKEDITOR.dom.element.createFromHtml( '<div><p> \n \n A<br> \n \n </p></div>' ); 106 107 assert.areSame( '<p>A</p>', getDataProcessor().toDataFormat( element ) ); 108 }, 109 110 test_toDataFormat_8 : function() 111 { 112 var element = new CKEDITOR.dom.element.createFromHtml( '<div><p>A<br><br></p></div>' ); 113 114 assert.areSame( '<p>A<br /><br /></p>', getDataProcessor().toDataFormat( element ) ); 115 }, 116 117 test_toDataFormat_8 : function() 118 { 119 var element = new CKEDITOR.dom.element.createFromHtml( '<div><p>A<br><hr></p></div>' ); 120 121 // Both the following cases are acceptable. It depends on the way the browser parses the HTML. 122 try 123 { 124 // IE, Opera and Safari 125 assert.areSame( '<p>A</p><hr /><p></p>', getDataProcessor().toDataFormat( element ) ); 126 } 127 catch ( e ) 128 { 129 // FF 130 assert.areSame( '<p>A</p><hr />', getDataProcessor().toDataFormat( element ) ); 131 } 132 }, 133 134 test_toDataFormat_ticket_2695 : function() 135 { 136 var element = new CKEDITOR.dom.element.createFromHtml( '<div><pre>\n\ 137 FOR A = 0 TO 255\n\ 138 PRINT CHR$(A);\n\ 139 NEXT A\n\ 140 </pre></div>' ); 141 142 assert.areSame( '<pre>FOR A = 0 TO 255\n\ 143 PRINT CHR$(A);\n\ 144 NEXT A\n\ 145 </pre>', getDataProcessor().toDataFormat( element ).replace( /\r\n|\r|\n/g, '\n' ) ); // Normalize line breaks for IE 146 }, 147 82 148 test_toDataFormat_ticket_2774 : function() 83 149 { 84 150 var element = new CKEDITOR.dom.element.createFromHtml( '<div><P class=MsoNormal><B><I><SPAN lang=EN-US><o:p>Test</o:p></SPAN></I></B></P></div>' );