Ticket #3441: 3441_5.patch

File 3441_5.patch, 5.0 KB (added by Garry Yao, 15 years ago)
  • _source/core/htmlparser/text.js

     
    55
    66(function()
    77{
     8        // cdataNode : Element tag names which contains CDATA data type.
    89        var spacesRegex = /[\t\r\n ]{2,}|[\t\r\n]/g;
    910
    1011        /**
     
    1213         * @constructor
    1314         * @example
    1415         */
    15         CKEDITOR.htmlParser.text = function( value )
     16        CKEDITOR.htmlParser.text = function( value )
    1617        {
    1718                /**
    1819                 * The text value.
     
    4445                 */
    4546                writeHtml : function( writer, filter )
    4647                {
    47                         var text = this.value;
     48                        var text = this.value,
     49                                textType =
     50                                        this.parent.name in CKEDITOR.dtd.$cdata ? 'CDATA' : 'Text';
    4851
    49                         if ( filter && !( text = filter.onText( text ) ) )
     52                        if ( filter && !( text = filter[ 'on' + textType ].call( filter, text ) ) )
    5053                                return;
    5154
    52                         writer.text( text );
     55                        writer.text( text, textType  == 'CDATA' );
    5356                }
    5457        };
    5558})();
  • _source/core/htmlparser/filter.js

     
    5656                        {
    5757                                return filterName( name, this._.attributeNames );
    5858                        },
    59 
     59                       
     60                        /**
     61                         * Filtering text node content.
     62                         * @param {Object} text The text content.
     63                         */
    6064                        onText : function( text )
    6165                        {
    6266                                var textFilter = this._.text;
     
    6266                                var textFilter = this._.text;
    6367                                return textFilter ? textFilter.filter( text ) : text;
    6468                        },
     69       
     70                        /**
     71                         * Filtering CDATA section content.
     72                         */
     73                        onCDATA : function( cdata )
     74                        {
     75                                var filter = this._.cdata;
     76                                return filter ? filter.filter( cdata ) : cdata;
     77                        },
    6578
    6679                        onComment : function( commentText )
    6780                        {
  • _source/core/htmlparser.js

     
    101102                {
    102103                        var parts,
    103104                                tagName,
    104                                 nextIndex = 0;
     105                                nextIndex = 0,
     106                                cdataMode = false,
     107                                cdataText = []; // The collected text content inside CDATA Section.
    105108
    106109                        while ( ( parts = this._.htmlPartsRegex.exec( html ) ) )
    107110                        {
     
    107110                        {
    108111                                var tagIndex = parts.index;
    109112                                if ( tagIndex > nextIndex )
    110                                         this.onText( html.substring( nextIndex, tagIndex ) );
    111 
    112                                 nextIndex = this._.htmlPartsRegex.lastIndex;
    113 
     113                                {
     114                                        var text = html.substring( nextIndex, tagIndex );
     115                                        if ( cdataMode )
     116                                                cdataText.push( text );                                 
     117                                        else
     118                                                this.onText( text );
     119                                }
     120                               
    114121                                /*
    115122                                 "parts" is an array with the following items:
    116                                         0 : The entire match (not used)
     123                                        0 : The entire match for opening/closing tags.
    117124                                        1 : Group filled with the tag name for closing tags.
    118125                                        2 : Group filled with the comment text.
    119126                                        3 : Group filled with the tag name for opening tags.
     
    119126                                        3 : Group filled with the tag name for opening tags.
    120127                                        4 : Group filled with the attributes part of opening tags.
    121128                                 */
     129                                nextIndex = this._.htmlPartsRegex.lastIndex;
     130                                // Treate tags as plain text.
     131                                if ( cdataMode )
     132                                        nextIndex-= parts[ 0 ].length;
    122133
    123134                                // Closing tag
    124135                                if ( ( tagName = parts[ 1 ] ) )
     
    123134                                // Closing tag
    124135                                if ( ( tagName = parts[ 1 ] ) )
    125136                                {
    126                                         this.onTagClose( tagName.toLowerCase() );
     137                                        if ( !cdataMode || tagName in CKEDITOR.dtd.$cdata )
     138                                        {
     139                                                if ( cdataMode )
     140                                                {
     141                                                        // Creating CDATA text.
     142                                                        this.onText( cdataText.join('') );
     143                                                        nextIndex+= parts[ 0 ].length;
     144                                                        cdataText = [];
     145                                                        cdataMode = false;
     146                                                }
     147                                                this.onTagClose( tagName.toLowerCase() );
     148                                        }
    127149                                        continue;
    128150                                }
    129151
     152                                // Ignore all tags matching inside CDATA section.
     153                                if ( cdataMode )
     154                                        continue;
     155
    130156                                // Opening tag
    131157                                if ( ( tagName = parts[ 3 ] ) )
    132158                                {
     
    148174                                                                attribs[ attName ] = attValue;
    149175                                                }
    150176                                        }
     177                                       
     178                                        this.onTagOpen( tagName.toLowerCase(), attribs, selfClosing );
    151179
    152                                         this.onTagOpen( tagName.toLowerCase(), attribs, selfClosing );
     180                                        // Open CDATA    mode when encounting accordinate tags.
     181                                        if ( tagName in CKEDITOR.dtd.$cdata )
     182                                                cdataMode = true;
    153183                                        continue;
    154184                                }
    155185
     
    156186                                // Comment
    157187                                if( ( tagName = parts[ 2 ] ) )
    158188                                        this.onComment( tagName );
     189                               
    159190                        }
    160191
    161192                        if ( html.length > nextIndex )
  • _source/core/dtd.js

     
    6767                $block : block,
    6868
    6969                $body : X({script:1}, block),
    70 
     70               
     71                $cdata : { script:1,style:1},
    7172                /**
    7273                 * List of empty (self-closing) elements, like "br" or "img".
    7374                 * @type Object
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy