Changeset 4275
- Timestamp:
- 09/22/09 18:39:30 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
CKEditor/branches/features/pasting/_source/plugins/pastefromword/plugin.js
r4271 r4275 59 59 60 60 // TODO: Support more list style type from MS-Word. 61 if ( bulletStyle[ 2 ] ) 61 if( !bulletStyle ) 62 { 63 bulletStyle = 'decimal'; 64 listType = 'ol'; 65 } 66 else if ( bulletStyle[ 2 ] ) 62 67 { 63 68 if ( !isNaN( bulletStyle[ 1 ] ) ) … … 74 79 else 75 80 { 76 if ( bulletStyle[ 1 ].search(/[l ·•]/) != -1 )81 if ( bulletStyle[ 1 ].search(/[l\u00B7\u2002]/) != -1 ) //l·• 77 82 bulletStyle = 'disc'; 78 else if ( bulletStyle[ 1 ].search(/[ oØ]/) != -1 )83 else if ( bulletStyle[ 1 ].search(/[\u006F\u00D8]/) != -1 ) //oØ 79 84 bulletStyle = 'circle'; 80 else if ( bulletStyle[ 1 ].search(/[ n◆]/) != -1 )85 else if ( bulletStyle[ 1 ].search(/[\u006E\u25C6]/) != -1 ) //n◆ 81 86 bulletStyle = 'square'; 82 87 else … … 101 106 if( /mso-list:\s*Ignore/i.test( styleText ) ) 102 107 return true; 108 }, 109 110 resolveList : function( element ) 111 { 112 // <cke:listbullet> lies inside indicate a list item. 113 var children = element.children, 114 attrs = element.attributes, 115 listMarker; 116 if( ( listMarker = element.anyChildWithName( 'cke:listbullet' ) ) 117 && listMarker.length 118 && ( listMarker = listMarker[ 0 ] ) ) 119 { 120 element.name = 'cke:li'; 121 attrs.style = CKEDITOR.plugins.pastefromword.filters.stylesFilter( 122 [ 123 [ 'text-indent' ], 124 [ 'margin-left', null, function( value ) 125 { 126 // Resolve indent level from 'margin-left' style. 127 attrs[ 'cke:indent' ] = parseInt( value ); 128 } ] 129 ] )( attrs.style, element ) || '' ; 130 131 // Inherit list-type-style from bullet. 132 var listBulletAttrs = listMarker.attributes, 133 listBulletStyle = listBulletAttrs.style; 134 135 attrs.style += listBulletStyle; 136 CKEDITOR.tools.extend( attrs, listBulletAttrs ); 137 children.splice( 0, 1 ); 138 return true; 139 } 103 140 } 104 141 … … 185 222 element.name = styleDef.element; 186 223 CKEDITOR.tools.extend( element.attributes, CKEDITOR.tools.clone( styleDef.attributes ) ); 187 var attrs = element.attributes; 188 attrs.style = ( attrs.style || '' ) + CKEDITOR.style.getStyleText( styleDef ); 224 element.addStyle( CKEDITOR.style.getStyleText( styleDef ) ); 189 225 } 190 226 }, … … 235 271 createListBulletMarker = this.utils.createListBulletMarker, 236 272 isListBulletIndicator = this.utils.isListBulletIndicator, 273 resolveList = this.utils.resolveList, 237 274 listDtdParents = CKEDITOR.dtd.parentOf( 'ol' ), 238 275 config = editor.config, … … 257 294 { 258 295 element.filterChildren(); 259 var onlyChild = element.onlyChild(); 260 // Remove empty headings. 261 if( onlyChild && onlyChild.value 262 && !CKEDITOR.tools.trim( onlyChild.value ) ) 263 return false; 264 delete element.attributes; 296 // Heading might be a list. 297 if( resolveList( element ) ) 298 return; 299 265 300 // Migrate heading formatting to editor configured ones. 266 301 elementMigrateFilter( config[ 'format_' + tagName ] )( element ); … … 274 309 delete element.name; 275 310 } 276 // Remove namespaced element while preserving the content.311 // Remove ms-office namespaced element while preserving the content. 277 312 else if( tagName.indexOf( ':' ) != -1 278 313 && tagName.indexOf( 'cke' ) == -1 ) … … 391 426 { 392 427 if( attrs && attrs.style ) 393 parent.attributes.style += ( attrs.style + ';' ); 428 parent.addStyle( attrs.style ); 429 394 430 delete element.name; 395 431 return; 396 432 } 397 // <cke:listbullet> lies inside any paragraph indicate a list item. 398 var childs; 399 if( ( childs = element.anyChildWithName( 'cke:listbullet' ) ) 400 && childs.length ) 401 { 402 var listMaker = childs[ 0 ]; 403 element.name = 'cke:li'; 404 attrs.style = stylesFilter( 405 [ 406 [ 'text-indent' ], 407 [ 'margin-left', null, function( value ) 408 { 409 // Resolve indent level from 'margin-left' style. 410 attrs[ 'cke:indent' ] = parseInt( value ); 411 } ] 412 ] )( attrs.style, element ) || '' ; 413 414 // Inherit list-type-style from bullet. 415 var listBulletAttrs = listMaker.attributes, 416 listBulletStyle = listBulletAttrs.style; 417 418 attrs.style += listBulletStyle; 419 CKEDITOR.tools.extend( attrs, listBulletAttrs ); 420 children.splice( 0, 1 ); 433 434 // Paragraph might be a list. 435 if( resolveList( element ) ) 421 436 return; 422 }423 437 424 438 // Migrate paragraph formatting based on editor's enter-mode. … … 510 524 attrs.style = stylesFilter( 511 525 [ 512 [ 'font-family', null, styleMigrateFilter( config[ 'font_style' ], 'family' ) ],526 [ /^font-family$/, null, styleMigrateFilter( config[ 'font_style' ], 'family' ) ], 513 527 // TODO: Convert 'pt' length unit into 'px'. 514 [ 'font-size', null, styleMigrateFilter( config[ 'fontSize_style' ], 'size' ) ],528 [ /^font-size$/, null, styleMigrateFilter( config[ 'fontSize_style' ], 'size' ) ], 515 529 // TODO: Convert 'rgb' and 'descriptive' color into 'hexadecimal'. 516 530 [ /^color$/, null, styleMigrateFilter( config[ 'colorButton_foreStyle' ], 'color' ) ], 517 [ 'background-color', null, styleMigrateFilter( config[ 'colorButton_backStyle' ], 'color' ) ]531 [ /^background-color$/, null, styleMigrateFilter( config[ 'colorButton_backStyle' ], 'color' ) ] 518 532 ] )( styleText, element ) || ''; 519 533 }, … … 556 570 [ /mso-/ ], 557 571 [ /-moz-/ ], 558 // Replace verbose background color style.559 [ /^background$/, null, function( value )560 {561 return value.match( /^[^\s]+/ )[ 0 ];562 }, 'background-color' ],563 572 [ 'background-color', 'transparent' ], 564 // Remove verbose border-color style within Firefox. 565 CKEDITOR.env.gecko ? [ 'border-color', /(:?windowtext|-moz-use-text-color|\s)*/ ] : null, 573 // Firefox: replacing Mozilla-specific color value. 574 CKEDITOR.env.gecko ? [ '-color', null, function( value, element ) 575 { 576 return value.replace( /-moz-use-text-color/g, 'transparent' ); 577 } ]: null, 578 // Remove default border style. 579 [ /^border$/, /^(:?medium\s*)?none\s*$/ ], 566 580 // 'Indent' format migration(to use editor's indent unit). 567 581 [ /margin-?/, null, function( value, element ) … … 569 583 if( element.name == 'p' ) 570 584 { 585 //TODO: Migrate to 'indentClasses' based indenting format. 571 586 value = value.replace( /\d*\.?\d+pt/g, function( length ) 572 587 { 573 588 var pt = parseInt( length ); 574 // Assume MS-Word indent unit length as '11pt'.575 return ( pt / 11 * config.indentOffset ) + config.indentUnit;589 // MS-Word indent unit is roughly 11pt. 590 return Math.round( pt / 11 * config.indentOffset ) + config.indentUnit; 576 591 } ); 577 592 } … … 599 614 }, 600 615 601 // We always have both 'text-align' style company with 602 // 'align' attribute, drop the attribute. 603 'align' : falsyFilter 616 // MS-Word always generate both 'text-align' along with 617 // 'align' attribute( 'background-color' along with 'bgcolor'), 618 // simply drop the deprecated attributes. 619 'align' : falsyFilter, 620 'bgcolor' : falsyFilter, 621 // Deprecate 'valign' attribute in favor of 'vertical-align'. 622 'valign' : function( value, element ) 623 { 624 // TODO: The style chang doesn't work now because of filtering system. 625 if( value != 'top' ) 626 element.addStyle( 'vertical-align', value ); 627 return false; 628 }, 629 630 // Avoid table 'border' attribute in favor of cell border styles. 631 'border' : function( value, element ) 632 { 633 if( element.name == 'table' ) 634 return false; 635 } 604 636 }, 605 637 … … 660 692 return childs; 661 693 }; 694 695 // Adding a (set) of styles to the element's attributes. 696 elementPrototype.addStyle = function( name, value ) 697 { 698 var styleText, addingStyleText = ''; 699 // style literal. 700 if( typeof name == 'object' ) 701 { 702 for( var style in name ) 703 { 704 if( name.hasOwnProperty( style) ) 705 addingStyleText += style + ':' + name[ style ] + ';'; 706 } 707 } 708 // name/value pair. 709 else if( value ) 710 addingStyleText += name + ':' + value + ';'; 711 // raw style text form. 712 else 713 addingStyleText += name; 714 715 if( !this.attributes ) 716 this.attributes = {}; 717 styleText = this.attributes.style; 718 if( !styleText ) 719 this.attributes.style = ""; 720 else if( !/;$/.test( styleText ) ) 721 this.attributes.style = styleText + ';'; 722 723 this.attributes.style += addingStyleText; 724 } 662 725 663 726 fragmentPrototype.firstTextChild = elementPrototype.firstTextChild = function()
Note: See TracChangeset
for help on using the changeset viewer.
