Ticket #3715: 3715.patch

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

     
    3636
    3737        var dtd                 = CKEDITOR.dtd,
    3838                isBlockLike     = !!( dtd.$block[ name ] || dtd.$listItem[ name ] || dtd.$tableContent[ name ] ),
     39                isPre = name == 'pre';
    3940                isEmpty         = !!dtd.$empty[ name ];
    4041
    4142        this.isEmpty    = isEmpty;
     
    4546        this._ =
    4647        {
    4748                isBlockLike : isBlockLike,
     49                isPre : isPre,
    4850                hasInlineStarted : isEmpty || !isBlockLike
    4951        };
    5052};
     
    124126                                        if ( !( element = filter.onElement( element ) ) )
    125127                                                return;
    126128
    127                                         if ( element.name == writeName )
     129                                        // Element already get serialized.
     130                                        if ( typeof element == 'string' )
     131                                        {
     132                                                writer.write(element);
     133                                                return;
     134                                        }
     135                                        else if ( element.name == writeName )
    128136                                                break;
    129137
    130138                                        writeName = element.name;
  • _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;
    51 
    5251                        writer.text( text );
    5352                }
    5453        };
  • _source/core/htmlparser/fragment.js

     
    118118                        }
    119119
    120120                        // Rtrim empty spaces on block end boundary. (#3585)
    121                         if ( element._.isBlockLike )
     121                        if ( element._.isBlockLike
     122                                 && !element._.isPre )
    122123                        {
    123 
    124124                                var length = element.children.length,
    125125                                        lastChild = element.children[ length - 1 ],
    126126                                        text;
  • _source/core/htmlparser/filter.js

     
    5757                                return filterName( name, this._.attributeNames );
    5858                        },
    5959
    60                         onText : function( text )
     60                        onText : function( text , node )
    6161                        {
    6262                                var textFilter = this._.text;
    63                                 return textFilter ? textFilter.filter( text ) : text;
     63                                return textFilter ? textFilter.filter( text, node ) : text;
    6464                        },
    6565
    6666                        onComment : function( commentText )
     
    8787                                                if ( ret === false )
    8888                                                        return null;
    8989
     90                                                // Element might been transformed into text node.
     91                                                if( ret && ret.type == CKEDITOR.NODE_TEXT )
     92                                                        return this.onText( ret.value, ret );
     93                                               
    9094                                                if ( ret && ret != element )
    9195                                                        return this.onElement( ret );
    9296                                        }
     
    212216                                if ( ret === false )
    213217                                        return false;
    214218
    215                                 if ( isObject && ret != currentEntry )
     219                                // 1. Stop further filtering if current filter has changed the
     220                                // element.
     221                                // 2. Make sure we safely return last filtering result.
     222                                if ( isObject && ret != currentEntry
     223                                        || i == this.length -1 )
    216224                                        return ret;
    217225                        }
    218226                }
  • _source/plugins/htmldataprocessor/plugin.js

     
    5656                        block.add( new CKEDITOR.htmlParser.text( '\xa0' ) );
    5757        }
    5858
     59        /**
     60         * Filter function for shrinking consequential spaces into one single white
     61         * space in text node.
     62         * Note: This behavior is IE's default treatment for all text node within
     63         * non-pre, we generalize to all browers to reach consistent result.
     64         * @param text
     65         */
     66        function compressSpaces( text , node )
     67        {
     68                if ( node.parent.name != 'pre' )
     69                        return text.replace( /[\t\r\n ]{2,}|[\t\r\n]/g, ' ' );
     70                else
     71                        return text;
     72        }
     73
    5974        var dtd = CKEDITOR.dtd;
    6075       
    6176        // Find out the list of block-like tags that can contain <br>.
     
    6580                if ( ! ( 'br' in dtd[i] ) )
    6681                        delete blockLikeTags[i];
    6782        }
    68 
     83        // We just avoid filler in <pre> right now.
     84        // TODO: Support filler for <pre>, line break is also occupy line height.
     85        delete blockLikeTags.pre;
    6986        var defaultDataFilterRules =
    7087        {
    7188                elementNames :
     
    8299                ]
    83100        };
    84101
     102        defaultDataFilterRules.text = compressSpaces;
     103
    85104        var defaultDataBlockFilterRules = { elements : {} };
    86105
    87106        for ( var i in blockLikeTags )
     
    120139
    121140                        elements :
    122141                        {
     142                                br : function( node )
     143                                {
     144                                        // Gecko had been replacing all linebreaks into <br>s, which
     145                                        // are required to be restored here.
     146                                        if ( node.parent.name == 'pre' )
     147                                        {
     148                                                var parent = node.parent;
     149                                                node = new CKEDITOR.htmlParser.text( '\n' );
     150                                                node.parent = parent;
     151                                        }
     152                                        return node;
     153                                },
     154
    123155                                embed : function( element )
    124156                                {
    125157                                        var parent = element.parent;
     
    169201                        }
    170202                };
    171203
     204        defaultHtmlFilterRules.text = compressSpaces;
    172205        var defaultHtmlBlockFilterRules = { elements : {} };
    173206       
    174207        for ( var i in blockLikeTags )
     
    211244        CKEDITOR.htmlDataProcessor = function()
    212245        {
    213246                this.writer = new CKEDITOR.htmlWriter();
     247                // Disable indentation on <pre>.
     248                this.writer.setRules( 'pre',
     249                {
     250                  indent: false
     251                } );
    214252                this.dataFilter = new CKEDITOR.htmlParser.filter();
    215253                this.htmlFilter = new CKEDITOR.htmlParser.filter();
    216254        };
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy