Ticket #3715: 3715_2.patch

File 3715_2.patch, 6.3 KB (added by Garry Yao, 15 years ago)
  • _source/core/htmlparser/text.js

     
    1919                 * @type String
    2020                 * @example
    2121                 */
    22                 this.value = value.replace( spacesRegex, ' ' );
     22                this.value = value;
    2323
    2424                /** @private */
    2525                this._ =
     
    4646                {
    4747                        var text = this.value;
    4848
    49                         if ( filter && !( text = filter.onText( text ) ) )
     49                        if ( filter && !( text = filter.onText( text, this ) ) )
    5050                                return;
    5151
    5252                        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       
     13CKEDITOR.plugins.load( 'htmlwriter' );
     14var tc;
     15CKEDITOR.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>
     75inside<br /> <br /></b>
     76
     77pre
     78</pre></textarea>
     79        <textarea id="htmlResult1"><pre>
     80        text<b>
     81inside
     82 
     83</b>
     84
     85pre
     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

     
    6464                        fragment = new CKEDITOR.htmlParser.fragment(),
    6565                        pendingInline = [],
    6666                        currentNode = fragment,
     67                    // Indicate we're inside a <pre> element, spaces should be touched differently.
     68                        inPre = false,
    6769                        returnPoint;
    6870
    6971                function checkPending( newTagName )
     
    118120                        }
    119121
    120122                        // Rtrim empty spaces on block end boundary. (#3585)
    121                         if ( element._.isBlockLike )
     123                        if ( element._.isBlockLike
     124                                 && inPre )
    122125                        {
    123126
    124127                                var length = element.children.length,
     
    157160                                pendingInline.push( element );
    158161                                return;
    159162                        }
     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                        }
    160170
    161171                        var currentName = currentNode.name,
    162172                                currentDtd = ( currentName && CKEDITOR.dtd[ currentName ] ) || ( currentNode._.isBlockLike ? CKEDITOR.dtd.div : CKEDITOR.dtd.span );
     
    263273
    264274                                currentNode = candidate;
    265275
     276                                if( currentNode.name == 'pre' )
     277                                        inPre = false;
     278
    266279                                addElement( candidate, candidate.parent );
    267280
    268281                                // The parent should start receiving new nodes now, except if
     
    290303
    291304                parser.onText = function( text )
    292305                {
    293                         if ( !currentNode._.hasInlineStarted )
     306                        // Trim empty spaces at beginning of element contents except <pre>.
     307                        if ( !currentNode._.hasInlineStarted && !inPre )
    294308                        {
    295309                                text = CKEDITOR.tools.ltrim( text );
    296310
     
    303317                        if ( fixForBody && !currentNode.type )
    304318                                this.onTagOpen( fixForBody, {} );
    305319
     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
    306325                        currentNode.add( new CKEDITOR.htmlParser.text( text ) );
    307326                };
    308327
  • _source/plugins/htmldataprocessor/plugin.js

     
    6565                if ( ! ( 'br' in dtd[i] ) )
    6666                        delete blockLikeTags[i];
    6767        }
    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;
    6971        var defaultDataFilterRules =
    7072        {
    7173                elementNames :
     
    234236        CKEDITOR.htmlDataProcessor = function()
    235237        {
    236238                this.writer = new CKEDITOR.htmlWriter();
     239                // Disable indentation on <pre>.
     240                this.writer.setRules( 'pre',
     241                {
     242                  indent: false
     243                } );
    237244                this.dataFilter = new CKEDITOR.htmlParser.filter();
    238245                this.htmlFilter = new CKEDITOR.htmlParser.filter();
    239246        };
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy