Ticket #7839: 7839.patch

File 7839.patch, 5.5 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/pastefromword/filter/default.js

     
    279279                                                                                var listId = Number( val[ 0 ].match( /\d+/ ) ),
    280280                                                                                        indent = Number( val[ 1 ].match( /\d+/ ) );
    281281
    282                                                                                 listId !== previousListId && ( attrs[ 'cke:reset' ] = 1 );
    283                                                                                 previousListId = listId;
     282                                                                                if ( indent == 1 )
     283                                                                                {
     284                                                                                        listId !== previousListId && ( attrs[ 'cke:reset' ] = 1 );
     285                                                                                        previousListId = listId;
     286                                                                                }
    284287                                                                                attrs[ 'cke:indent' ] = indent;
    285288                                                                        } ]
    286289                                                                ] )( attrs.style, element ) || '';
     
    357360                                // E.g. <ul><li>level1<ol><li>level2</li></ol></li> =>
    358361                                // <cke:li cke:listtype="ul" cke:indent="1">level1</cke:li>
    359362                                // <cke:li cke:listtype="ol" cke:indent="2">level2</cke:li>
    360                                 flattenList : function( element )
     363                                flattenList : function( element, level )
    361364                                {
     365                                        level = typeof level == 'number' ? level : 1;
     366
    362367                                        var     attrs = element.attributes,
    363                                                 parent = element.parent;
     368                                                listStyleType;
    364369
    365                                         var listStyleType,
    366                                                 indentLevel = 1;
    367 
    368                                         // Resolve how many level nested.
    369                                         while ( parent )
    370                                         {
    371                                                 parent.attributes && parent.attributes[ 'cke:list' ] && indentLevel++;
    372                                                 parent = parent.parent;
    373                                         }
    374 
    375370                                        // All list items are of the same type.
    376371                                        switch ( attrs.type )
    377372                                        {
    378373                                                case 'a' :
    379374                                                        listStyleType = 'lower-alpha';
    380375                                                        break;
     376                                                case '1' :
     377                                                        listStyleType = 'decimal';
     378                                                        break;
    381379                                                // TODO: Support more list style type from MS-Word.
    382380                                        }
    383381
    384382                                        var children = element.children,
    385                                                 child;
     383                                                child,
     384                                                index;
    386385
    387386                                        for ( var i = 0; i < children.length; i++ )
    388387                                        {
    389388                                                child = children[ i ];
    390                                                 var attributes = child.attributes;
     389                                                if ( child.name == 'li' )
     390                                                {
     391                                                        var attributes = child.attributes;
    391392
    392                                                 if ( child.name in CKEDITOR.dtd.$listItem )
    393                                                 {
    394                                                         var listItemChildren = child.children,
    395                                                                 count = listItemChildren.length,
    396                                                                 last = listItemChildren[ count - 1 ];
     393                                                        if ( child.name in CKEDITOR.dtd.$listItem )
     394                                                        {
     395                                                                var listItemChildren = child.children,
     396                                                                        count = listItemChildren.length,
     397                                                                        last = listItemChildren[ count - 1 ];
    397398
    398                                                         // Move out nested list.
    399                                                         if ( last.name in CKEDITOR.dtd.$list )
    400                                                         {
    401                                                                 children.splice( i + 1, 0, last );
    402                                                                 last.parent = element;
     399                                                                // Move out nested list.
     400                                                                if ( last.name in CKEDITOR.dtd.$list )
     401                                                                {
     402                                                                        children.splice( i + 1, 0, last );
     403                                                                        last.parent = element;
    403404
    404                                                                 // Remove the parent list item if it's just a holder.
    405                                                                 if ( !--listItemChildren.length )
    406                                                                         children.splice( i, 1 );
    407                                                         }
     405                                                                        // Remove the parent list item if it's just a holder.
     406                                                                        if ( !--listItemChildren.length )
     407                                                                                children.splice( i, 1 );
     408
     409                                                                        // Flatten sub list.
     410                                                                        arguments.callee.apply( this, [ last, level + 1 ] );
     411                                                                        var index = children.indexOf( last );
     412                                                                        // Absorb sub list children.
     413                                                                        children = children.splice( 0, index ).concat( last.children ).concat( children.splice( index + 1 ) );
     414                                                                        element.children = children;
     415                                                                }
    408416
    409                                                         child.name = 'cke:li';
     417                                                                child.name = 'cke:li';
    410418
    411                                                         // Inherit numbering from list root on the first list item.
    412                                                         attrs.start && !i && ( attributes.value = attrs.start );
     419                                                                // Inherit numbering from list root on the first list item.
     420                                                                attrs.start && !i && ( attributes.value = attrs.start );
    413421
    414                                                         plugin.filters.stylesFilter(
    415                                                                 [
    416                                                                     [ 'tab-stops', null, function( val )
    417                                                                         {
    418                                                                                 var margin = val.split( ' ' )[ 1 ].match( cssLengthRelativeUnit );
    419                                                                                 margin && ( previousListItemMargin = parseInt( plugin.utils.convertToPx( margin[ 0 ] ), 10 ) );
    420                                                                         } ],
    421                                                                         [ 'mso-list', null, function( val )
    422                                                                         {
    423                                                                                 val = val.split( ' ' );
    424                                                                                 var listId = Number( val[ 0 ].match( /\d+/ ) );
    425                                                                                 listId !== previousListId && ( attributes[ 'cke:reset' ] = 1 );
    426                                                                                 previousListId = listId;
    427                                                                         } ]
    428                                                                 ] )( attributes.style );
     422                                                                plugin.filters.stylesFilter(
     423                                                                        [
     424                                                                                [ 'tab-stops', null, function( val )
     425                                                                                {
     426                                                                                        var margin = val.split( ' ' )[ 1 ].match( cssLengthRelativeUnit );
     427                                                                                        margin && ( previousListItemMargin = parseInt( plugin.utils.convertToPx( margin[ 0 ] ), 10 ) );
     428                                                                                } ],
     429                                                                                ( level == 1 ? [ 'mso-list', null, function( val )
     430                                                                                {
     431                                                                                        val = val.split( ' ' );
     432                                                                                        var listId = Number( val[ 0 ].match( /\d+/ ) );
     433                                                                                        listId !== previousListId && ( attributes[ 'cke:reset' ] = 1 );
     434                                                                                        previousListId = listId;
     435                                                                                 } ] : null )
     436                                                                        ] )( attributes.style );
    429437
    430                                                         attributes[ 'cke:indent' ] = indentLevel;
    431                                                         attributes[ 'cke:listtype' ] = element.name;
    432                                                         attributes[ 'cke:list-style-type' ] = listStyleType;
    433                                                 }
    434                                         }
     438                                                                attributes[ 'cke:indent' ] = level;
     439                                                                attributes[ 'cke:listtype' ] = element.name;
     440                                                                attributes[ 'cke:list-style-type' ] = listStyleType;
     441                                                        }
     442                                                }
     443                                        }
    435444
    436445                                        delete element.name;
    437446
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy