Ticket #3407: 3407_5.patch

File 3407_5.patch, 4.3 KB (added by Frederico Caldeira Knabben, 15 years ago)
  • _source/core/config.js

     
    170170         * config.removePlugins = 'elementspath,save,font';
    171171         */
    172172        removePlugins : '',
     173       
     174        /**
     175         * List of regular expressions to be executed over the input HTML,
     176         * indicating code that must stay untouched.
     177         * @type Array
     178         * @example
     179         * config.protectedSource.push( /<\?[\s\S]*?\?>/g );   // PHP Code
     180         * config.protectedSource.push( /<%[\s\S]*?%>/g );   // ASP Code
     181         * config.protectedSource.push( /(<asp:[^\>]+>[\s|\S]*?<\/asp:[^\>]+>)|(<asp:[^\>]+\/>)/gi );   // ASP.Net Code
     182         */
     183        protectedSource : [],
    173184
    174185        /**
    175186         * The editor tabindex value.
  • _source/core/htmlparser/comment.js

     
    4242        {
    4343                var comment = this.value;
    4444
    45                 if ( filter && !( comment = filter.onComment( comment ) ) )
    46                         return;
     45                if ( filter )
     46                {
     47                        if ( !( comment = filter.onComment( comment ) ) )
     48                                return;
     49                       
     50                        if ( typeof comment != 'string' )
     51                        {
     52                                comment.writeHtml( writer, filter );
     53                                return;
     54                        }
     55                }
    4756
    4857                writer.comment( comment );
    4958        }
  • _source/plugins/htmldataprocessor/plugin.js

     
    88        // Regex to scan for &nbsp; at the end of blocks, which are actually placeholders.
    99        var tailNbspRegex = /^[\t\r\n ]*&nbsp;$/;
    1010
     11        var protectedSourceMarker = '{cke_protected}';
     12
    1113        function trimFillers( block, fromSource )
    1214        {
    1315                // If the current node is a block, and if we're converting from source or
     
    168170                                        // Remove all class names starting with "cke_".
    169171                                        return CKEDITOR.tools.ltrim( value.replace( /(?:^|\s+)cke_[^\s]*/g, '' ) ) || false;
    170172                                }
     173                        },
     174
     175                        comment : function( contents )
     176                        {
     177                                if ( contents.substr( 0, protectedSourceMarker.length ) == protectedSourceMarker )
     178                                        return new CKEDITOR.htmlParser.cdata( decodeURIComponent( contents.substr( protectedSourceMarker.length ) ) );
     179
     180                                return contents;
    171181                        }
    172182                };
    173183
     
    216226                return html.replace( encodedTagsRegex, unprotectEncodedTagsMatch );
    217227        }
    218228
     229        function protectSource( data, protectRegexes )
     230        {
     231                var regexes =
     232                        [
     233                                // First of any other protection, we must protect all comments
     234                                // to avoid loosing them (of course, IE related).
     235                                /<!--[\s\S]*?-->/g,
     236
     237                                // Script tags will also be forced to be protected, otherwise
     238                                // IE will execute them.
     239                                /<script[\s\S]*?<\/script>/gi,
     240
     241                                // <noscript> tags (get lost in IE and messed up in FF).
     242                                /<noscript[\s\S]*?<\/noscript>/gi
     243                        ]
     244                        .concat( protectRegexes );
     245               
     246                for ( var i = 0 ; i < regexes.length ; i++ )
     247                {
     248                        data = data.replace( regexes[i], function( match )
     249                                {
     250                                        return '<!--' + protectedSourceMarker + encodeURIComponent( match ).replace( /--/g, '%2D%2D' ) + '-->';
     251                                });
     252                }
     253               
     254                return data;
     255        }
     256
    219257        CKEDITOR.plugins.add( 'htmldataprocessor',
    220258        {
    221259                requires : [ 'htmlwriter' ],
    222260
    223261                init : function( editor )
    224262                {
    225                         var dataProcessor = editor.dataProcessor = new CKEDITOR.htmlDataProcessor();
     263                        var dataProcessor = editor.dataProcessor = new CKEDITOR.htmlDataProcessor( editor );
    226264
    227265                        dataProcessor.writer.forceSimpleAmpersand = editor.config.forceSimpleAmpersand;
    228266
     
    233271                }
    234272        });
    235273
    236         CKEDITOR.htmlDataProcessor = function()
     274        CKEDITOR.htmlDataProcessor = function( editor )
    237275        {
     276                this.editor = editor;
     277
    238278                this.writer = new CKEDITOR.htmlWriter();
    239279                this.dataFilter = new CKEDITOR.htmlParser.filter();
    240280                this.htmlFilter = new CKEDITOR.htmlParser.filter();
     
    247287                        // The source data is already HTML, but we need to clean
    248288                        // it up and apply the filter.
    249289
     290                        data = protectSource( data, this.editor.config.protectedSource );
     291
    250292                        // Before anything, we must protect the URL attributes as the
    251293                        // browser may changing them when setting the innerHTML later in
    252294                        // the code.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy