Ticket #3715: 3715_3.patch
File 3715_3.patch, 6.5 KB (added by , 14 years ago) |
---|
-
_source/plugins/htmlwriter/plugin.js
78 78 breakAfterClose : true 79 79 }); 80 80 } 81 82 81 this.setRules( 'br', 83 82 { 84 83 breakAfterOpen : true 85 84 }); 85 // Disable indentation on <pre>. 86 this.setRules( 'pre', 87 { 88 indent: false 89 } ); 86 90 }, 87 91 88 92 proto : -
_source/core/htmlparser/text.js
19 19 * @type String 20 20 * @example 21 21 */ 22 this.value = value .replace( spacesRegex, ' ' );22 this.value = value; 23 23 24 24 /** @private */ 25 25 this._ = … … 46 46 { 47 47 var text = this.value; 48 48 49 if ( filter && !( text = filter.onText( text ) ) )49 if ( filter && !( text = filter.onText( text, this ) ) ) 50 50 return; 51 51 52 52 writer.text( text ); -
_source/tests/core/htmlparser/htmlparser.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <title>CKEDITOR.htmlParser</title> 5 <link rel="stylesheet" type="text/css" href="../../test.css" /> 6 <script type="text/javascript" src="../../../../ckeditor_source.js"></script> <!-- %REMOVE_LINE% 7 <script type="text/javascript" src="../../../ckeditor.js"></script> 8 %REMOVE_LINE% --> 9 <script type="text/javascript" src="../../test.js"></script> 10 <script type="text/javascript"> 11 //<![CDATA[ 12 13 CKEDITOR.plugins.load( 'htmlwriter' ); 14 var tc; 15 CKEDITOR.test.addTestCase( tc = ( function() 16 { 17 // Local reference to the "assert" object. 18 var assert = YAHOO.util.Assert; 19 20 /** 21 * Wrapper of the combination of htmlParser with htmlWriter, for convenience of 22 * testing, formatting of writer has been disabled. 23 */ 24 function htmlParse( htmlString , writerConfig) 25 { 26 var writer = new CKEDITOR.htmlParser.basicWriter(); 27 writer.reset(); 28 var fragment = CKEDITOR.htmlParser.fragment.fromHtml( htmlString ); 29 fragment.writeHtml( writer ); 30 return writer.getHtml(); 31 } 32 33 /** 34 * IE always returning CRLF for line-feed, so remove it when retrieving 35 * pre-formated text from text area. 36 */ 37 function getTextAreaValue( id ) 38 { 39 return CKEDITOR.document.getById( id ).getValue().replace( /\r/gi, '' ); 40 } 41 42 return 43 { 44 /** 45 * Test <pre> tag formatting. 46 */ 47 test_fromHtml_3715 : function() 48 { 49 assert.areSame( getTextAreaValue( 'htmlResult1' ), 50 htmlParse( getTextAreaValue( 'htmlOriginal1' ) ), 51 '<pre> parsing result doesn\'t match.' ); 52 }, 53 54 /** 55 * Test compress empty spaces within text. 56 */ 57 test_fromHtml_3715_2 : function() 58 { 59 assert.areSame( getTextAreaValue( 'htmlResult2' ), 60 htmlParse( getTextAreaValue( 'htmlOriginal2' ) ), 61 'Spaces compressing result doesn\'t match.' ); 62 }, 63 name :document.title 64 }; 65 } )() ); 66 67 //window.onload = tc.test_fromHtml_3715; 68 //]]> 69 </script> 70 </head> 71 <body> 72 73 <textarea id="htmlOriginal1"><pre> 74 text<b> 75 inside<br /> <br /></b> 76 77 pre 78 </pre></textarea> 79 <textarea id="htmlResult1"><pre> 80 text<b> 81 inside 82 83 </b> 84 85 pre 86 </pre></textarea> 87 88 <textarea id="htmlOriginal2"><p> 89 para graph 90 </p><b>compress spaces</b></textarea> 91 92 <textarea id="htmlResult2"><p>para graph </p><b>compress spaces</b></textarea> 93 </body> 94 </html> -
_source/core/htmlparser/fragment.js
64 64 fragment = new CKEDITOR.htmlParser.fragment(), 65 65 pendingInline = [], 66 66 currentNode = fragment, 67 // Indicate we're inside a <pre> element, spaces should be touched differently. 68 inPre = false, 67 69 returnPoint; 68 70 69 71 function checkPending( newTagName ) … … 118 120 } 119 121 120 122 // Rtrim empty spaces on block end boundary. (#3585) 121 if ( element._.isBlockLike ) 123 if ( element._.isBlockLike 124 && inPre ) 122 125 { 123 126 124 127 var length = element.children.length, … … 157 160 pendingInline.push( element ); 158 161 return; 159 162 } 163 else if ( tagName == 'pre' ) 164 inPre = true; 165 else if ( tagName == 'br' && inPre ) 166 { 167 currentNode.add( new CKEDITOR.htmlParser.text( '\n' ) ); 168 return; 169 } 160 170 161 171 var currentName = currentNode.name, 162 172 currentDtd = ( currentName && CKEDITOR.dtd[ currentName ] ) || ( currentNode._.isBlockLike ? CKEDITOR.dtd.div : CKEDITOR.dtd.span ); … … 263 273 264 274 currentNode = candidate; 265 275 276 if( currentNode.name == 'pre' ) 277 inPre = false; 278 266 279 addElement( candidate, candidate.parent ); 267 280 268 281 // The parent should start receiving new nodes now, except if … … 290 303 291 304 parser.onText = function( text ) 292 305 { 293 if ( !currentNode._.hasInlineStarted ) 306 // Trim empty spaces at beginning of element contents except <pre>. 307 if ( !currentNode._.hasInlineStarted && !inPre ) 294 308 { 295 309 text = CKEDITOR.tools.ltrim( text ); 296 310 … … 303 317 if ( fixForBody && !currentNode.type ) 304 318 this.onTagOpen( fixForBody, {} ); 305 319 320 // Shrinking consequential spaces into one single for all elements 321 // text contents. 322 if ( !inPre ) 323 text = text.replace( /[\t\r\n ]{2,}|[\t\r\n]/g, ' ' ); 324 306 325 currentNode.add( new CKEDITOR.htmlParser.text( text ) ); 307 326 }; 308 327 -
_source/plugins/htmldataprocessor/plugin.js
65 65 if ( ! ( 'br' in dtd[i] ) ) 66 66 delete blockLikeTags[i]; 67 67 } 68 68 // We just avoid filler in <pre> right now. 69 // TODO: Support filler for <pre>, line break is also occupy line height. 70 delete blockLikeTags.pre; 69 71 var defaultDataFilterRules = 70 72 { 71 73 elementNames :