Ticket #3441: 3441_7.patch

File 3441_7.patch, 6.2 KB (added by Frederico Caldeira Knabben, 15 years ago)
  • _source/core/dtd.js

     
    6868
    6969                $body : X({script:1}, block),
    7070
     71                $cdata : { script:1,style:1},
     72
    7173                /**
    7274                 * List of empty (self-closing) elements, like "br" or "img".
    7375                 * @type Object
  • _source/core/htmlparser.js

     
    7373                onText          : function() {},
    7474
    7575                /**
     76                 * Function to be fired when CDATA section is found. This function
     77                 * should be overriden when using this class.
     78                 * @param {String} cdata The CDATA been found.
     79                 * @example
     80                 * var parser = new CKEDITOR.htmlParser();
     81                 * parser.onCDATA = function( cdata )
     82                 *     {
     83                 *         alert( cdata );  // e.g. "var hello;"
     84                 *     });
     85                 * parser.parse( "<script>var hello;</script>" );
     86                 */
     87                onCDATA         : function() {},
     88
     89                /**
    7690                 * Function to be fired when a commend is found. This function
    7791                 * should be overriden when using this class.
    7892                 * @param {String} comment The comment text.
     
    101115                {
    102116                        var parts,
    103117                                tagName,
    104                                 nextIndex = 0;
     118                                nextIndex = 0,
     119                                cdata;  // The collected data inside a CDATA section.
    105120
    106121                        while ( ( parts = this._.htmlPartsRegex.exec( html ) ) )
    107122                        {
    108123                                var tagIndex = parts.index;
    109124                                if ( tagIndex > nextIndex )
    110                                         this.onText( html.substring( nextIndex, tagIndex ) );
     125                                {
     126                                        var text = html.substring( nextIndex, tagIndex );
    111127
     128                                        if ( cdata )
     129                                                cdata.push( text );                                     
     130                                        else
     131                                                this.onText( text );
     132                                }
     133
    112134                                nextIndex = this._.htmlPartsRegex.lastIndex;
    113135
    114136                                /*
    115137                                 "parts" is an array with the following items:
    116                                         0 : The entire match (not used)
     138                                        0 : The entire match for opening/closing tags and comments.
    117139                                        1 : Group filled with the tag name for closing tags.
    118140                                        2 : Group filled with the comment text.
    119141                                        3 : Group filled with the tag name for opening tags.
     
    123145                                // Closing tag
    124146                                if ( ( tagName = parts[ 1 ] ) )
    125147                                {
    126                                         this.onTagClose( tagName.toLowerCase() );
     148                                        tagName = tagName.toLowerCase();
     149
     150                                        if ( cdata && CKEDITOR.dtd.$cdata[ tagName ] )
     151                                        {
     152                                                // Send the CDATA data.
     153                                                this.onCDATA( cdata.join('') );
     154                                                cdata = null;
     155                                        }
     156
     157                                        if ( !cdata )
     158                                        {
     159                                                this.onTagClose( tagName );
     160                                                continue;
     161                                        }
     162                                }
     163
     164                                // If CDATA is enabled, just save the raw match.
     165                                if ( cdata )
     166                                {
     167                                        cdata.push( parts[ 0 ] );
    127168                                        continue;
    128169                                }
    129170
     
    150191                                        }
    151192
    152193                                        this.onTagOpen( tagName.toLowerCase(), attribs, selfClosing );
     194
     195                                        // Open CDATA mode when finding the appropriate tags.
     196                                        if ( !cdata && CKEDITOR.dtd.$cdata[ tagName ] )
     197                                                cdata = [];
     198
    153199                                        continue;
    154200                                }
    155201
  • _source/core/htmlparser/cdata.js

     
     1/*
     2Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     3For licensing, see LICENSE.html or http://ckeditor.com/license
     4*/
     5
     6(function()
     7{
     8
     9        /**
     10         * A lightweight representation of HTML text.
     11         * @constructor
     12         * @example
     13         */
     14        CKEDITOR.htmlParser.cdata = function( value )
     15        {
     16                /**
     17                 * The CDATA value.
     18                 * @type String
     19                 * @example
     20                 */
     21                this.value = value;
     22
     23        };
     24
     25        CKEDITOR.htmlParser.cdata.prototype =
     26        {
     27                /**
     28                 * CDATA has the same type as {@link CKEDITOR.htmlParser.text} This is
     29                 * a constant value set to {@link CKEDITOR.NODE_TEXT}.
     30                 * @type Number
     31                 * @example
     32                 */
     33                type : CKEDITOR.NODE_TEXT,
     34
     35                /**
     36                 * Writes write the CDATA with no special manipulations.
     37                 * @param {CKEDITOR.htmlWriter} writer The writer to which write the HTML.
     38                 */
     39                writeHtml : function( writer )
     40                {
     41                        writer.write( this.value );
     42                }
     43        };
     44})();
  • _source/core/htmlparser/fragment.js

     
    289289                        currentNode.add( new CKEDITOR.htmlParser.text( text ) );
    290290                };
    291291
     292                parser.onCDATA = function( cdata )
     293                {
     294                        currentNode.add( new CKEDITOR.htmlParser.cdata( cdata ) );
     295                };
     296
    292297                parser.onComment = function( comment )
    293298                {
    294299                        currentNode.add( new CKEDITOR.htmlParser.comment( comment ) );
  • _source/core/loader.js

     
    5353                        'core/htmlparser'               : [],
    5454                        'core/htmlparser/comment'       : [ 'core/htmlparser' ],
    5555                        'core/htmlparser/element'       : [ 'core/htmlparser', 'core/htmlparser/fragment' ],
    56                         'core/htmlparser/fragment'      : [ 'core/htmlparser', 'core/htmlparser/comment', 'core/htmlparser/text' ],
     56                        'core/htmlparser/fragment'      : [ 'core/htmlparser', 'core/htmlparser/comment', 'core/htmlparser/text', 'core/htmlparser/cdata' ],
    5757                        'core/htmlparser/text'          : [ 'core/htmlparser' ],
     58                        'core/htmlparser/cdata'         : [ 'core/htmlparser' ],
    5859                        'core/htmlparser/filter'        : [ 'core/htmlparser' ],
    5960                        'core/htmlparser/basicwriter': [ 'core/htmlparser' ],
    6061                        'core/imagecacher'              : [ 'core/dom/element' ],
  • _source/tests/core/htmlparser/fragment.html

     
    145145                                                '<p>1</p><div>2</div><p><span>3</span></p>' );
    146146                },
    147147
     148                test_ticket_3441 : function()
     149                {
     150                        testParser(     '<p><b>Test</b></p><script type="test">var a = "<A Href=xxx>Testing</ A>";\nGo();<\/script>',
     151                                                '<p><b>Test</b></p><script type="test">var a = "<A Href=xxx>Testing</ A>";\nGo();<\/script>' );
     152                },
     153
    148154                name : document.title
    149155        };
    150156})() );
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy