Ticket #4729: 4729.patch

File 4729.patch, 11.6 KB (added by Frederico Caldeira Knabben, 14 years ago)
  • _source/core/dom/comment.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/**
     7 * @fileOverview Defines the {@link CKEDITOR.dom.comment} class, which represents
     8 *              a DOM comment node.
     9 */
     10
     11CKEDITOR.dom.comment = CKEDITOR.tools.createClass(
     12{
     13        base : CKEDITOR.dom.node,
     14
     15        $ : function( text, ownerDocument )
     16        {
     17                if ( typeof text == 'string' )
     18                        text = ( ownerDocument ? ownerDocument.$ : document ).createComment( text );
     19
     20                this.base( text );
     21        },
     22       
     23        proto :
     24        {
     25                type : CKEDITOR.NODE_COMMENT,
     26               
     27                getText : function()
     28                {
     29                        return this.$.nodeValue;
     30                },
     31               
     32                getOuterHtml : function()
     33                {
     34                        return '<!--' + this.getText() + '-->';
     35                }
     36        }
     37});
     38 No newline at end of file
  • _source/core/htmlparser/element.js

     
    3434         */
    3535        this.children = [];
    3636
     37        var tagName = attributes._cke_real_element_type || name;
     38
    3739        var dtd                 = CKEDITOR.dtd,
    38                 isBlockLike     = !!( dtd.$block[ name ] || dtd.$listItem[ name ] || dtd.$tableContent[ name ] || dtd.$nonEditable[ name ] || name == 'br' ),
     40                isBlockLike     = !!( dtd.$block[ tagName ] || dtd.$listItem[ tagName ] || dtd.$tableContent[ tagName ] || dtd.$nonEditable[ tagName ] || tagName == 'br' ),
    3941                isEmpty         = !!dtd.$empty[ name ];
    4042
    4143        this.isEmpty    = isEmpty;
     
    127129                                        if ( element.name == writeName )
    128130                                                break;
    129131
     132                                        // If the element has been replaced with something of a
     133                                        // different type, then make the replacement write itself.
     134                                        if ( element.type != CKEDITOR.NODE_ELEMENT )
     135                                        {
     136                                                element.writeHtml( writer, filter );
     137                                                return;
     138                                        }
     139
    130140                                        writeName = element.name;
    131141                                        if ( !writeName )       // Send children.
    132142                                        {
  • _source/core/htmlparser/filter.js

     
    8888                                                        return null;
    8989
    9090                                                if ( ret && ret != element )
    91                                                         return this.onElement( ret );
     91                                                        return this.onNode( ret );
    9292                                        }
    9393                                }
    9494
    9595                                return element;
    9696                        },
    9797
     98                        onNode : function( node )
     99                        {
     100                                var type = node.type;
     101                               
     102                                return type == CKEDITOR.NODE_ELEMENT ? this.onElement( node ) :
     103                                        type == CKEDITOR.NODE_TEXT ? new CKEDITOR.htmlParser.text( this.onText( node.value ) ) :
     104                                        type == CKEDITOR.NODE_COMMENT ? new CKEDITOR.htmlParser.comment( this.onComment( node.value ) ):
     105                                        null;
     106                        },
     107
    98108                        onAttribute : function( element, name, value )
    99109                        {
    100110                                var filter = this._.attributes[ name ];
  • _source/core/loader.js

     
    2323                // Table of script names and their dependencies.
    2424                var scripts =
    2525                {
    26                         'core/_bootstrap'               : [ 'core/config', 'core/ckeditor', 'core/plugins', 'core/scriptloader', 'core/tools', /* The following are entries that we want to force loading at the end to avoid dependence recursion */ 'core/dom/elementpath', 'core/dom/text', 'core/dom/range' ],
     26                        'core/_bootstrap'               : [ 'core/config', 'core/ckeditor', 'core/plugins', 'core/scriptloader', 'core/tools', /* The following are entries that we want to force loading at the end to avoid dependence recursion */ 'core/dom/comment', 'core/dom/elementpath', 'core/dom/text', 'core/dom/range' ],
    2727                        'core/ajax'                             : [ 'core/xml' ],
    2828                        'core/ckeditor'                 : [ 'core/ckeditor_basic', 'core/dom', 'core/dtd', 'core/dom/document', 'core/dom/element', 'core/editor', 'core/event', 'core/htmlparser', 'core/htmlparser/element', 'core/htmlparser/fragment', 'core/htmlparser/filter', 'core/htmlparser/basicwriter', 'core/tools' ],
    2929                        'core/ckeditor_base'    : [],
     
    3131                        'core/command'                  : [],
    3232                        'core/config'                   : [ 'core/ckeditor_base' ],
    3333                        'core/dom'                              : [],
     34                        'core/dom/comment'              : [ 'core/dom/node' ],
    3435                        'core/dom/document'             : [ 'core/dom', 'core/dom/domobject', 'core/dom/window' ],
    3536                        'core/dom/documentfragment'     : [ 'core/dom/element' ],
    3637                        'core/dom/element'              : [ 'core/dom', 'core/dom/document', 'core/dom/domobject', 'core/dom/node', 'core/dom/nodelist', 'core/tools' ],
  • _source/plugins/fakeobjects/plugin.js

     
    6363CKEDITOR.editor.prototype.createFakeElement = function( realElement, className, realElementType, isResizable )
    6464{
    6565        var lang = this.lang.fakeobjects;
     66
    6667        var attributes =
    6768        {
    6869                'class' : className,
    6970                src : CKEDITOR.getUrl( 'images/spacer.gif' ),
    7071                _cke_realelement : encodeURIComponent( realElement.getOuterHtml() ),
     72                _cke_real_node_type : realElement.type,
    7173                alt : lang[ realElementType ] || lang.unknown
    7274        };
     75
    7376        if ( realElementType )
    7477                attributes._cke_real_element_type = realElementType;
     78
    7579        if ( isResizable )
    7680                attributes._cke_resizable = isResizable;
    7781
     
    8084
    8185CKEDITOR.editor.prototype.createFakeParserElement = function( realElement, className, realElementType, isResizable )
    8286{
     87        var lang = this.lang.fakeobjects,
     88                html, writer;
     89
    8390        var writer = new CKEDITOR.htmlParser.basicWriter();
    84 
    8591        realElement.writeHtml( writer );
     92        html = writer.getHtml();
    8693
    87         var html = writer.getHtml();
    88         var lang = this.lang.fakeobjects;
    89 
    9094        var attributes =
    9195        {
    9296                'class' : className,
    9397                src : CKEDITOR.getUrl( 'images/spacer.gif' ),
    9498                _cke_realelement : encodeURIComponent( html ),
     99                _cke_real_node_type : realElement.type,
    95100                alt : lang[ realElementType ] || lang.unknown
    96101        };
    97102
     
    106111
    107112CKEDITOR.editor.prototype.restoreRealElement = function( fakeElement )
    108113{
    109         var html = decodeURIComponent( fakeElement.getAttribute( '_cke_realelement' ) );
    110         return CKEDITOR.dom.element.createFromHtml( html, this.document );
     114        if ( fakeElement.getAttribute( '_cke_real_node_type' ) == CKEDITOR.NODE_COMMENT )
     115                return null;
     116
     117        return CKEDITOR.dom.element.createFromHtml(
     118                decodeURIComponent( fakeElement.getAttribute( '_cke_realelement' ) ),
     119                this.document );
    111120};
  • _source/plugins/htmldataprocessor/plugin.js

     
    1111
    1212        var protectedSourceMarker = '{cke_protected}';
    1313
    14 
    1514        // Return the last non-space child node of the block (#4344).
    1615        function lastNoneSpaceChild( block )
    1716        {
     
    177176
    178177                        comment : function( contents )
    179178                        {
     179                                // If this is a comment for protected source.
    180180                                if ( contents.substr( 0, protectedSourceMarker.length ) == protectedSourceMarker )
    181                                         return new CKEDITOR.htmlParser.cdata( decodeURIComponent( contents.substr( protectedSourceMarker.length ) ) );
     181                                {
     182                                        // Remove the extra marker for real comments from it.
     183                                        if ( contents.substr( protectedSourceMarker.length, 3 ) == '{C}' )
     184                                                contents = contents.substr( protectedSourceMarker.length + 3 );
     185                                        else
     186                                                contents = contents.substr( protectedSourceMarker.length );
    182187
     188                                        return new CKEDITOR.htmlParser.cdata( decodeURIComponent( contents ) );
     189                                }
     190
    183191                                return contents;
    184192                        }
    185193                };
     
    239247                return html.replace( encodedTagsRegex, unprotectEncodedTagsMatch );
    240248        }
    241249
     250        function unprotectRealComments( html )
     251        {
     252                return html.replace( /<!--{cke_protected}{C}([\s\S]+?)-->/g, function( match, data )
     253                        {
     254                                return decodeURIComponent( data );
     255                        });
     256        }
     257
     258        function protectRealComments( html )
     259        {
     260                return html.replace( /<!--(?!{cke_protected})[\s\S]+?-->/g, function( match )
     261                        {
     262                                return '<!--' + protectedSourceMarker +
     263                                                '{C}' +
     264                                                encodeURIComponent( match ).replace( /--/g, '%2D%2D' ) +
     265                                                '-->';
     266                        });
     267        }
     268
    242269        function protectSource( data, protectRegexes )
    243270        {
    244271                var protectedHtml = [],
    245                         tempRegex = /<\!--\{cke_temp\}(\d*?)-->/g;
     272                        tempRegex = /<\!--\{cke_temp(comment)?\}(\d*?)-->/g;
     273
    246274                var regexes =
    247275                        [
    248                                 // First of any other protection, we must protect all comments
    249                                 // to avoid loosing them (of course, IE related).
    250                                 (/<!--[\s\S]*?-->/g),
    251 
    252276                                // Script tags will also be forced to be protected, otherwise
    253277                                // IE will execute them.
    254278                                /<script[\s\S]*?<\/script>/gi,
     
    258282                        ]
    259283                        .concat( protectRegexes );
    260284
     285                // First of any other protection, we must protect all comments
     286                // to avoid loosing them (of course, IE related).
     287                // Note that we use a different tag for comments, as we need to
     288                // transform them when applying filters.
     289                data = data.replace( (/<!--[\s\S]*?-->/g), function( match )
     290                        {
     291                                return  '<!--{cke_tempcomment}' + ( protectedHtml.push( match ) - 1 ) + '-->';
     292                        });
     293
    261294                for ( var i = 0 ; i < regexes.length ; i++ )
    262295                {
    263296                        data = data.replace( regexes[i], function( match )
    264297                                {
    265298                                        match = match.replace( tempRegex,               // There could be protected source inside another one. (#3869).
    266                                                 function( $, id )
     299                                                function( $, isComment, id )
    267300                                                {
    268301                                                        return protectedHtml[ id ];
    269302                                                }
     
    271304                                        return  '<!--{cke_temp}' + ( protectedHtml.push( match ) - 1 ) + '-->';
    272305                                });
    273306                }
    274                 data = data.replace( tempRegex, function( $, id )
     307                data = data.replace( tempRegex, function( $, isComment, id )
    275308                        {
    276309                                return '<!--' + protectedSourceMarker +
     310                                                ( isComment ? '{C}' : '' ) +
    277311                                                encodeURIComponent( protectedHtml[ id ] ).replace( /--/g, '%2D%2D' ) +
    278312                                                '-->';
    279313                        }
     
    291325
    292326                        dataProcessor.writer.forceSimpleAmpersand = editor.config.forceSimpleAmpersand;
    293327
    294                         dataProcessor.dataFilter.addRules( defaultDataFilterRules );
    295                         dataProcessor.dataFilter.addRules( defaultDataBlockFilterRules );
    296                         dataProcessor.htmlFilter.addRules( defaultHtmlFilterRules );
    297                         dataProcessor.htmlFilter.addRules( defaultHtmlBlockFilterRules );
     328                        // Rules are added with lower priority so, by default, other rules
     329                        // provided by end developers will be executed first.
     330                        dataProcessor.dataFilter.addRules( defaultDataFilterRules, 20 );
     331                        dataProcessor.dataFilter.addRules( defaultDataBlockFilterRules, 20 );
     332                        dataProcessor.htmlFilter.addRules( defaultHtmlFilterRules, 20 );
     333                        dataProcessor.htmlFilter.addRules( defaultHtmlBlockFilterRules, 20 );
    298334                }
    299335        });
    300336
     
    343379                        if ( CKEDITOR.env.ie )
    344380                                data = unprotectEncodedTags( data );
    345381
     382                        // Restore the comments that have been protected, in this way they
     383                        // can be properly filtered.
     384                        data = unprotectRealComments( data );
     385
    346386                        // Now use our parser to make further fixes to the structure, as
    347387                        // well as apply the filter.
    348388                        var fragment = CKEDITOR.htmlParser.fragment.fromHtml( data, fixForBody ),
    349389                                writer = new CKEDITOR.htmlParser.basicWriter();
    350390
    351391                        fragment.writeHtml( writer, this.dataFilter );
     392                        data = writer.getHtml( true );
    352393
    353                         return writer.getHtml( true );
     394                        // Protect the real comments again.
     395                        data = protectRealComments( data );
     396
     397                        return data;
    354398                },
    355399
    356400                toDataFormat : function( html, fixForBody )
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy