Ticket #7646: 7646_3.patch

File 7646_3.patch, 11.3 KB (added by Garry Yao, 12 years ago)
  • _source/core/htmlparser/cdata.js

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    3333
    3434                /**
    3535                 * Writes write the CDATA with no special manipulations.
    36                  * @param {CKEDITOR.htmlWriter} writer The writer to which write the HTML.
     36                 * @param {CKEDITOR.htmlWriter} [writer] The writer to which write the HTML.
    3737                 */
    3838                writeHtml : function( writer )
    3939                {
    40                         writer.write( this.value );
     40                        writer && writer.write( this.value );
    4141                }
    4242        };
    4343})();
  • _source/core/htmlparser/fragment.js

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    513513                {
    514514                        for ( var i = 0 ; i < this.children.length ; i++ )
    515515                                this.children[i].writeHtml( writer, filter );
     516                },
     517
     518                /**
     519                 * Dry-run the specified filter on this node and its children without outputting.
     520                 * @see {#writeHtml}
     521                 * @param filter {CKEDITOR.htmlParser.filter}
     522                 */
     523                filterHtml : function( filter )
     524                {
     525                        this.writeHtml( null, filter );
    516526                }
    517527        };
     528
     529
    518530})();
  • _source/core/htmlparser/comment.js

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    3535
    3636        /**
    3737         * Writes the HTML representation of this comment to a CKEDITOR.htmlWriter.
    38          * @param {CKEDITOR.htmlWriter} writer The writer to which write the HTML.
     38         * @param {CKEDITOR.htmlWriter} [writer] The writer to which write the HTML.
    3939         * @example
    4040         */
    4141        writeHtml : function( writer, filter )
     
    5353                                comment.writeHtml( writer, filter );
    5454                                return;
    5555                        }
     56
     57                        // Update node in case of filter dry-run.
     58                        this.value = comment;
    5659                }
    5760
    58                 writer.comment( comment );
     61                writer && writer.comment( comment );
    5962        }
    6063};
  • _source/core/htmlparser/element.js

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    191191                        {
    192192                                while ( true )
    193193                                {
    194                                         if ( !( writeName = filter.onElementName( writeName ) ) )
    195                                                 return;
     194                                        if ( writeName )
     195                                        {
     196                                                if ( !( writeName = filter.onElementName( writeName ) ) )
     197                                                        return;
    196198
    197                                         element.name = writeName;
     199                                                element.name = writeName;
    198200
    199                                         if ( !( element = filter.onElement( element ) ) )
    200                                                 return;
     201                                                if ( !( element = filter.onElement( element ) ) )
     202                                                        return;
    201203
    202                                         element.parent = this.parent;
     204                                                element.parent = this.parent;
    203205
    204                                         if ( element.name == writeName )
    205                                                 break;
     206                                                if ( element.name == writeName )
     207                                                        break;
    206208
    207                                         // If the element has been replaced with something of a
    208                                         // different type, then make the replacement write itself.
    209                                         if ( element.type != CKEDITOR.NODE_ELEMENT )
    210                                         {
    211                                                 element.writeHtml( writer, filter );
    212                                                 return;
    213                                         }
     209                                                // If the element has been replaced with something of a
     210                                                // different type, then make the replacement write itself.
     211                                                if ( element.type != CKEDITOR.NODE_ELEMENT )
     212                                                {
     213                                                        element.writeHtml( writer, filter );
     214                                                        return;
     215                                                }
     216                                        }
    214217
    215218                                        writeName = element.name;
    216219
     
    233236                        }
    234237
    235238                        // Open element tag.
    236                         writer.openTag( writeName, attributes );
     239                        writer && writer.openTag( writeName, attributes );
    237240
    238241                        // Copy all attributes to an array.
    239242                        var attribsArray = [];
     
    275278                                        }
    276279                                }
    277280                        }
    278                         // Sort the attributes by name.
    279                         if ( writer.sortAttributes )
    280                                 attribsArray.sort( sortAttribs );
     281
     282                        if ( writer )
     283                        {
     284                                // Sort the attributes by name.
     285                                if ( writer.sortAttributes )
     286                                        attribsArray.sort( sortAttribs );
    281287
    282                         // Send the attributes.
    283                         var len = attribsArray.length;
    284                         for ( i = 0 ; i < len ; i++ )
    285                         {
    286                                 var attrib = attribsArray[ i ];
    287                                 writer.attribute( attrib[0], attrib[1] );
    288                         }
     288                                // Send the attributes.
     289                                var len = attribsArray.length;
     290                                for ( i = 0; i < len; i++ )
     291                                {
     292                                        var attrib = attribsArray[ i ];
     293                                        writer.attribute( attrib[0], attrib[1] );
     294                                }
    289295
    290                         // Close the tag.
    291                         writer.openTagClose( writeName, element.isEmpty );
     296                                // Close the tag.
     297                                writer.openTagClose( writeName, element.isEmpty );
     298                        }
    292299
    293300                        if ( !element.isEmpty )
    294301                        {
    295302                                this.writeChildrenHtml.call( element, writer, isChildrenFiltered ? null : filter );
    296303                                // Close the element.
    297                                 writer.closeTag( writeName );
     304                                writer && writer.closeTag( writeName );
    298305                        }
    299306                },
    300307
     
    303310                        // Send children.
    304311                        CKEDITOR.htmlParser.fragment.prototype.writeChildrenHtml.apply( this, arguments );
    305312
    306                 }
     313                },
     314
     315                /**
     316                 * @see CKEDITOR.htmlParser.fragment.prototype.filterHtml
     317                 */
     318                filterHtml : CKEDITOR.htmlParser.fragment.prototype.filterHtml
    307319        };
    308320})();
  • _source/plugins/htmldataprocessor/plugin.js

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    487487        {
    488488                toHtml : function( data, fixForBody )
    489489                {
     490                        // Fire "beforeProcessData" so data manipulation may happen.
     491                        var eventData = { data : data };
     492                        this.editor.fire( 'beforeProcessData', eventData );
     493                        data = eventData.data;
     494
    490495                        // The source data is already HTML, but we need to clean
    491496                        // it up and apply the filter.
    492497
     
    539544
    540545                        // Now use our parser to make further fixes to the structure, as
    541546                        // well as apply the filter.
    542                         var fragment = CKEDITOR.htmlParser.fragment.fromHtml( data, fixForBody ),
    543                                 writer = new CKEDITOR.htmlParser.basicWriter();
     547                        var fragment = CKEDITOR.htmlParser.fragment.fromHtml( data, fixForBody );
    544548
     549                        // Fire "beforeFilterData" to allow pre-filtering with custom rules.
     550                        this.editor.fire( 'beforeFilterData', { fragment : fragment } );
     551
     552                        // Run through the default filters.
     553                        var writer = new CKEDITOR.htmlParser.basicWriter();
    545554                        fragment.writeHtml( writer, this.dataFilter );
    546555                        data = writer.getHtml( true );
    547556
     
    553562
    554563                toDataFormat : function( html, fixForBody )
    555564                {
     565                        // Fire "beforeProcessHtml" so data manipulation may happen.
     566                        var eventData = { html : html };
     567                        this.editor.fire( 'beforeProcessHtml', eventData );
     568                        html = eventData.html;
     569
    556570                        var writer = this.writer,
    557571                                fragment = CKEDITOR.htmlParser.fragment.fromHtml( html, fixForBody );
     572
     573                        // Fire "beforeFilterHtml" to allow pre-filtering with custom rules.
     574                        this.editor.fire( 'beforeFilterHtml', { fragment : fragment } );
    558575
    559576                        writer.reset();
    560577
  • _source/plugins/pastefromword/filter/default.js

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    12721272                }
    12731273        });
    12741274
    1275         // The paste processor here is just a reduced copy of html data processor.
    1276         var pasteProcessor = function()
     1275        // These are instance-irrelevant rules for post cleanup which are applied afterward.
     1276        var cleanupFilter = new CKEDITOR.htmlParser.filter();
     1277        cleanupFilter.addRules(
    12771278        {
    1278                 this.dataFilter = new CKEDITOR.htmlParser.filter();
    1279         };
    1280 
    1281         pasteProcessor.prototype =
    1282         {
    1283                 toHtml : function( data )
    1284                 {
    1285                         var fragment = CKEDITOR.htmlParser.fragment.fromHtml( data, false ),
    1286                                 writer = new CKEDITOR.htmlParser.basicWriter();
    1287 
    1288                         fragment.writeHtml( writer, this.dataFilter );
    1289                         return writer.getHtml( true );
    1290                 }
    1291         };
     1279                attributeNames :
     1280                [
     1281                        // Remove onmouseover and onmouseout events (from MS Word comments effect)
     1282                        [ ( /^cke:.*/ ), '' ]
     1283                ],
     1284                attributes :
     1285                {
     1286                        'style' : function( value )
     1287                        {
     1288                                if ( !value )
     1289                                        return false;
     1290                        }
     1291                },
     1292                elements :
     1293                {
     1294                        'span' : function( element )
     1295                        {
     1296                                // Remove dummy spans (attribute-less).
     1297                                if ( CKEDITOR.tools.isEmpty( element.attributes ) )
     1298                                        element.name = '';
     1299                        }
     1300                }
     1301        });
    12921302
    12931303        CKEDITOR.cleanWord = function( data, editor )
    12941304        {
    1295                 // Firefox will be confused by those downlevel-revealed IE conditional
    1296                 // comments, fixing them first( convert it to upperlevel-revealed one ).
    1297                 // e.g. <![if !vml]>...<![endif]>
    1298                 if ( CKEDITOR.env.gecko )
    1299                         data = data.replace( /(<!--\[if[^<]*?\])-->([\S\s]*?)<!--(\[endif\]-->)/gi, '$1$2$3' );
     1305                // These rules are instance related logic that converting MS-HTML to html.
     1306                var defaultFilter = new CKEDITOR.htmlParser.filter();
     1307                defaultFilter.addRules( CKEDITOR.plugins.pastefromword.getRules( editor ) );
    13001308
    1301                 var dataProcessor = new pasteProcessor(),
    1302                         dataFilter = dataProcessor.dataFilter;
     1309                editor.on( 'beforeFilterData', function( evt )
     1310                {
     1311                        // Just for this run.
     1312                        evt.removeListener();
    13031313
    1304                 // These rules will have higher priorities than default ones.
    1305                 dataFilter.addRules( CKEDITOR.plugins.pastefromword.getRules( editor ) );
     1314                        var fragment = evt.data.fragment;
    13061315
    1307                 // Allow extending data filter rules.
    1308                 editor.fire( 'beforeCleanWord', { filter : dataFilter } );
     1316                        // Allow extending data filter rules.
     1317                        editor.fire( 'beforeCleanWord', { filter : defaultFilter } );
    13091318
    1310                 try
    1311                 {
    1312                         data = dataProcessor.toHtml( data, false );
    1313                 }
    1314                 catch ( e )
    1315                 {
    1316                         alert( editor.lang.pastefromword.error );
    1317                 }
     1319                        fragment.filterHtml( defaultFilter );
     1320                        fragment.filterHtml( cleanupFilter );
     1321                } );
    13181322
    1319                 /* Below post processing those things that are unable to delivered by filter rules. */
    1320 
    1321                 // Remove 'cke' namespaced attribute used in filter rules as marker.
    1322                 data = data.replace( /cke:.*?".*?"/g, '' );
    1323 
    1324                 // Remove empty style attribute.
    1325                 data = data.replace( /style=""/g, '' );
    1326 
    1327                 // Remove the dummy spans ( having no inline style ).
    1328                 data = data.replace( /<span>/g, '' );
     1323                // Firefox will be confused by those downlevel-revealed IE conditional
     1324                // comments, fixing them first( convert it to upperlevel-revealed one ).
     1325                // e.g. <![if !vml]>...<![endif]>
     1326                if ( CKEDITOR.env.gecko )
     1327                        data = data.replace( /(<!--\[if[^<]*?\])-->([\S\s]*?)<!--(\[endif\]-->)/gi, '$1$2$3' );
    13291328
    13301329                return data;
    13311330        };
  • _source/core/htmlparser/text.js

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    4444                {
    4545                        var text = this.value;
    4646
    47                         if ( filter && !( text = filter.onText( text, this ) ) )
    48                                 return;
     47                        if ( filter )
     48                        {
     49                                if ( !( text = filter.onText( text, this ) ) )
     50                                        return;
    4951
    50                         writer.text( text );
     52                                // Update node in case of filter dry-run.
     53                                this.value = text;
     54                        }
     55
     56                        writer && writer.text( text );
    5157                }
    5258        };
    5359})();
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy