JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4.3
[ckeditor.git] / _source / plugins / pastefromword / filter / default.js
1 /*\r
2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license\r
4 */\r
5 \r
6 (function()\r
7 {\r
8         var fragmentPrototype = CKEDITOR.htmlParser.fragment.prototype,\r
9                 elementPrototype = CKEDITOR.htmlParser.element.prototype;\r
10 \r
11         fragmentPrototype.onlyChild = elementPrototype.onlyChild = function()\r
12         {\r
13                 var children = this.children,\r
14                         count = children.length,\r
15                         firstChild = ( count == 1 ) && children[ 0 ];\r
16                 return firstChild || null;\r
17         };\r
18 \r
19         elementPrototype.removeAnyChildWithName = function( tagName )\r
20         {\r
21                 var children = this.children,\r
22                         childs = [],\r
23                         child;\r
24 \r
25                 for ( var i = 0; i < children.length; i++ )\r
26                 {\r
27                         child = children[ i ];\r
28                         if ( !child.name )\r
29                                 continue;\r
30 \r
31                         if ( child.name == tagName )\r
32                         {\r
33                                 childs.push( child );\r
34                                 children.splice( i--, 1 );\r
35                         }\r
36                         childs = childs.concat( child.removeAnyChildWithName( tagName ) );\r
37                 }\r
38                 return childs;\r
39         };\r
40 \r
41         elementPrototype.getAncestor = function( tagNameRegex )\r
42         {\r
43                 var parent = this.parent;\r
44                 while ( parent && !( parent.name && parent.name.match( tagNameRegex ) ) )\r
45                         parent = parent.parent;\r
46                 return parent;\r
47         };\r
48 \r
49         fragmentPrototype.firstChild = elementPrototype.firstChild = function( evaluator )\r
50         {\r
51                 var child;\r
52 \r
53                 for ( var i = 0 ; i < this.children.length ; i++ )\r
54                 {\r
55                         child = this.children[ i ];\r
56                         if ( evaluator( child ) )\r
57                                 return child;\r
58                         else if ( child.name )\r
59                         {\r
60                                 child = child.firstChild( evaluator );\r
61                                 if ( child )\r
62                                         return child;\r
63                         }\r
64                 }\r
65 \r
66                 return null;\r
67         };\r
68 \r
69         // Adding a (set) of styles to the element's 'style' attributes.\r
70         elementPrototype.addStyle = function( name, value, isPrepend )\r
71         {\r
72                 var styleText, addingStyleText = '';\r
73                 // name/value pair.\r
74                 if ( typeof value == 'string' )\r
75                         addingStyleText += name + ':' + value + ';';\r
76                 else\r
77                 {\r
78                         // style literal.\r
79                         if ( typeof name == 'object' )\r
80                         {\r
81                                 for ( var style in name )\r
82                                 {\r
83                                         if ( name.hasOwnProperty( style ) )\r
84                                                 addingStyleText += style + ':' + name[ style ] + ';';\r
85                                 }\r
86                         }\r
87                         // raw style text form.\r
88                         else\r
89                                 addingStyleText += name;\r
90 \r
91                         isPrepend = value;\r
92                 }\r
93 \r
94                 if ( !this.attributes )\r
95                         this.attributes = {};\r
96 \r
97                 styleText = this.attributes.style || '';\r
98 \r
99                 styleText = ( isPrepend ?\r
100                               [ addingStyleText, styleText ]\r
101                                           : [ styleText, addingStyleText ] ).join( ';' );\r
102 \r
103                 this.attributes.style = styleText.replace( /^;|;(?=;)/, '' );\r
104         };\r
105 \r
106         /**\r
107          * Return the DTD-valid parent tag names of the specified one.\r
108          * @param tagName\r
109          */\r
110         CKEDITOR.dtd.parentOf = function( tagName )\r
111         {\r
112                 var result = {};\r
113                 for ( var tag in this )\r
114                 {\r
115                         if ( tag.indexOf( '$' ) == -1 && this[ tag ][ tagName ] )\r
116                                 result[ tag ] = 1;\r
117                 }\r
118                 return result;\r
119         };\r
120 \r
121         var cssLengthRelativeUnit = /^([.\d]*)+(em|ex|px|gd|rem|vw|vh|vm|ch|mm|cm|in|pt|pc|deg|rad|ms|s|hz|khz){1}?/i;\r
122         var emptyMarginRegex = /^(?:\b0[^\s]*\s*){1,4}$/;               // e.g. 0px 0pt 0px\r
123         var romanLiternalPattern = '^m{0,4}(cm|cd|d?c{0,3})(xc|xl|l?x{0,3})(ix|iv|v?i{0,3})$',\r
124                 lowerRomanLiteralRegex = new RegExp( romanLiternalPattern ),\r
125                 upperRomanLiteralRegex = new RegExp( romanLiternalPattern.toUpperCase() );\r
126 \r
127         var listBaseIndent = 0,\r
128                  previousListItemMargin;\r
129 \r
130         CKEDITOR.plugins.pastefromword =\r
131         {\r
132                 utils :\r
133                 {\r
134                         // Create a <cke:listbullet> which indicate an list item type.\r
135                         createListBulletMarker : function ( bulletStyle, bulletText )\r
136                         {\r
137                                 var marker = new CKEDITOR.htmlParser.element( 'cke:listbullet' ),\r
138                                         listType;\r
139 \r
140                                 // TODO: Support more list style type from MS-Word.\r
141                                 if ( !bulletStyle )\r
142                                 {\r
143                                         bulletStyle = 'decimal';\r
144                                         listType = 'ol';\r
145                                 }\r
146                                 else if ( bulletStyle[ 2 ] )\r
147                                 {\r
148                                         if ( !isNaN( bulletStyle[ 1 ] ) )\r
149                                                 bulletStyle = 'decimal';\r
150                                         else if ( lowerRomanLiteralRegex.test( bulletStyle[ 1 ] ) )\r
151                                                 bulletStyle = 'lower-roman';\r
152                                         else if ( upperRomanLiteralRegex.test( bulletStyle[ 1 ] ) )\r
153                                                 bulletStyle = 'upper-roman';\r
154                                         else if ( /^[a-z]+$/.test( bulletStyle[ 1 ] ) )\r
155                                                 bulletStyle = 'lower-alpha';\r
156                                         else if ( /^[A-Z]+$/.test( bulletStyle[ 1 ] ) )\r
157                                                 bulletStyle = 'upper-alpha';\r
158                                         // Simply use decimal for the rest forms of unrepresentable\r
159                                         // numerals, e.g. Chinese...\r
160                                         else\r
161                                                 bulletStyle = 'decimal';\r
162 \r
163                                         listType = 'ol';\r
164                                 }\r
165                                 else\r
166                                 {\r
167                                         if ( /[l\u00B7\u2002]/.test( bulletStyle[ 1 ] ) )\r
168                                                 bulletStyle = 'disc';\r
169                                         else if ( /[\u006F\u00D8]/.test( bulletStyle[ 1 ] ) )\r
170                                                 bulletStyle = 'circle';\r
171                                         else if ( /[\u006E\u25C6]/.test( bulletStyle[ 1 ] ) )\r
172                                                 bulletStyle = 'square';\r
173                                         else\r
174                                                 bulletStyle = 'disc';\r
175 \r
176                                         listType = 'ul';\r
177                                 }\r
178 \r
179                                 // Represent list type as CSS style.\r
180                                 marker.attributes =\r
181                                 {\r
182                                         'cke:listtype' : listType,\r
183                                         'style' : 'list-style-type:' + bulletStyle + ';'\r
184                                 };\r
185                                 marker.add( new CKEDITOR.htmlParser.text( bulletText ) );\r
186                                 return marker;\r
187                         },\r
188 \r
189                         isListBulletIndicator : function( element )\r
190                         {\r
191                                 var styleText = element.attributes && element.attributes.style;\r
192                                 if ( /mso-list\s*:\s*Ignore/i.test( styleText ) )\r
193                                         return true;\r
194                         },\r
195 \r
196                         isContainingOnlySpaces : function( element )\r
197                         {\r
198                                 var text;\r
199                                 return ( ( text = element.onlyChild() )\r
200                                             && ( /^(:?\s|&nbsp;)+$/ ).test( text.value ) );\r
201                         },\r
202 \r
203                         resolveList : function( element )\r
204                         {\r
205                                 // <cke:listbullet> indicate a list item.\r
206                                 var attrs = element.attributes,\r
207                                         listMarker;\r
208 \r
209                                 if ( ( listMarker = element.removeAnyChildWithName( 'cke:listbullet' ) )\r
210                                           && listMarker.length\r
211                                           && ( listMarker = listMarker[ 0 ] ) )\r
212                                 {\r
213                                         element.name = 'cke:li';\r
214 \r
215                                         if ( attrs.style )\r
216                                         {\r
217                                                 attrs.style = CKEDITOR.plugins.pastefromword.filters.stylesFilter(\r
218                                                                 [\r
219                                                                         // Text-indent is not representing list item level any more.\r
220                                                                         [ 'text-indent' ],\r
221                                                                         [ 'line-height' ],\r
222                                                                         // Resolve indent level from 'margin-left' value.\r
223                                                                         [ ( /^margin(:?-left)?$/ ), null, function( margin )\r
224                                                                         {\r
225                                                                                 // Be able to deal with component/short-hand form style.\r
226                                                                                 var values = margin.split( ' ' );\r
227                                                                                 margin = CKEDITOR.plugins.pastefromword.utils.convertToPx( values[ 3 ] || values[ 1 ] || values [ 0 ] );\r
228                                                                                 margin = parseInt( margin, 10 );\r
229 \r
230                                                                                 // Figure out the indent unit by looking at the first increament.\r
231                                                                                 if ( !listBaseIndent && previousListItemMargin && margin > previousListItemMargin )\r
232                                                                                         listBaseIndent = margin - previousListItemMargin;\r
233 \r
234                                                                                 attrs[ 'cke:margin' ] = previousListItemMargin = margin;\r
235                                                                         } ]\r
236                                                         ] )( attrs.style, element ) || '' ;\r
237                                         }\r
238 \r
239                                         // Inherit list-type-style from bullet.\r
240                                         var listBulletAttrs = listMarker.attributes,\r
241                                                 listBulletStyle = listBulletAttrs.style;\r
242 \r
243                                         element.addStyle( listBulletStyle );\r
244                                         CKEDITOR.tools.extend( attrs, listBulletAttrs );\r
245                                         return true;\r
246                                 }\r
247 \r
248                                 return false;\r
249                         },\r
250 \r
251                         // Convert various length units to 'px' in ignorance of DPI.\r
252                         convertToPx : ( function ()\r
253                         {\r
254                                 var calculator = CKEDITOR.dom.element.createFromHtml(\r
255                                                                 '<div style="position:absolute;left:-9999px;' +\r
256                                                                 'top:-9999px;margin:0px;padding:0px;border:0px;"' +\r
257                                                                 '></div>', CKEDITOR.document );\r
258                                 CKEDITOR.document.getBody().append( calculator );\r
259 \r
260                                 return function( cssLength )\r
261                                 {\r
262                                         if ( cssLengthRelativeUnit.test( cssLength ) )\r
263                                         {\r
264                                                 calculator.setStyle( 'width', cssLength );\r
265                                                 return calculator.$.clientWidth + 'px';\r
266                                         }\r
267 \r
268                                         return cssLength;\r
269                                 };\r
270                         } )(),\r
271 \r
272                         // Providing a shorthand style then retrieve one or more style component values.\r
273                         getStyleComponents : ( function()\r
274                         {\r
275                                 var calculator = CKEDITOR.dom.element.createFromHtml(\r
276                                                                 '<div style="position:absolute;left:-9999px;top:-9999px;"></div>',\r
277                                                                 CKEDITOR.document );\r
278                                 CKEDITOR.document.getBody().append( calculator );\r
279 \r
280                                 return function( name, styleValue, fetchList )\r
281                                 {\r
282                                         calculator.setStyle( name, styleValue );\r
283                                         var styles = {},\r
284                                                 count = fetchList.length;\r
285                                         for ( var i = 0; i < count; i++ )\r
286                                                 styles[ fetchList[ i ] ]  = calculator.getStyle( fetchList[ i ] );\r
287 \r
288                                         return styles;\r
289                                 };\r
290                         } )(),\r
291 \r
292                         listDtdParents : CKEDITOR.dtd.parentOf( 'ol' )\r
293                 },\r
294 \r
295                 filters :\r
296                 {\r
297                                 // Transform a normal list into flat list items only presentation.\r
298                                 // E.g. <ul><li>level1<ol><li>level2</li></ol></li> =>\r
299                                 // <cke:li cke:listtype="ul" cke:indent="1">level1</cke:li>\r
300                                 // <cke:li cke:listtype="ol" cke:indent="2">level2</cke:li>\r
301                                 flattenList : function( element )\r
302                                 {\r
303                                         var     attrs = element.attributes,\r
304                                                 parent = element.parent;\r
305 \r
306                                         var listStyleType,\r
307                                                 indentLevel = 1;\r
308 \r
309                                         // Resolve how many level nested.\r
310                                         while ( parent )\r
311                                         {\r
312                                                 parent.attributes && parent.attributes[ 'cke:list'] && indentLevel++;\r
313                                                 parent = parent.parent;\r
314                                         }\r
315 \r
316                                         // All list items are of the same type.\r
317                                         switch ( attrs.type )\r
318                                         {\r
319                                                 case 'a' :\r
320                                                         listStyleType = 'lower-alpha';\r
321                                                         break;\r
322                                                 // TODO: Support more list style type from MS-Word.\r
323                                         }\r
324 \r
325                                         var children = element.children,\r
326                                                 child;\r
327 \r
328                                         for ( var i = 0; i < children.length; i++ )\r
329                                         {\r
330                                                 child = children[ i ];\r
331                                                 var attributes = child.attributes;\r
332 \r
333                                                 if ( child.name in CKEDITOR.dtd.$listItem )\r
334                                                 {\r
335                                                         var listItemChildren = child.children,\r
336                                                                 count = listItemChildren.length,\r
337                                                                 last = listItemChildren[ count - 1 ];\r
338 \r
339                                                         // Move out nested list.\r
340                                                         if ( last.name in CKEDITOR.dtd.$list )\r
341                                                         {\r
342                                                                 children.splice( i + 1, 0, last );\r
343                                                                 last.parent = element;\r
344 \r
345                                                                 // Remove the parent list item if it's just a holder.\r
346                                                                 if ( !--listItemChildren.length )\r
347                                                                         children.splice( i, 1 );\r
348                                                         }\r
349 \r
350                                                         child.name = 'cke:li';\r
351                                                         attributes[ 'cke:indent' ] = indentLevel;\r
352                                                         previousListItemMargin = 0;\r
353                                                         attributes[ 'cke:listtype' ] = element.name;\r
354                                                         listStyleType && child.addStyle( 'list-style-type', listStyleType, true );\r
355                                                 }\r
356                                         }\r
357 \r
358                                         delete element.name;\r
359 \r
360                                         // We're loosing tag name here, signalize this element as a list.\r
361                                         attrs[ 'cke:list' ] = 1;\r
362                                 },\r
363 \r
364                                 /**\r
365                                  *  Try to collect all list items among the children and establish one\r
366                                  *  or more HTML list structures for them.\r
367                                  * @param element\r
368                                  */\r
369                                 assembleList : function( element )\r
370                                 {\r
371                                         var children = element.children, child,\r
372                                                         listItem,   // The current processing cke:li element.\r
373                                                         listItemAttrs,\r
374                                                         listType,   // Determine the root type of the list.\r
375                                                         listItemIndent, // Indent level of current list item.\r
376                                                         lastListItem, // The previous one just been added to the list.\r
377                                                         list, parentList, // Current staging list and it's parent list if any.\r
378                                                         indent;\r
379 \r
380                                         for ( var i = 0; i < children.length; i++ )\r
381                                         {\r
382                                                 child = children[ i ];\r
383 \r
384                                                 if ( 'cke:li' == child.name )\r
385                                                 {\r
386                                                         child.name = 'li';\r
387                                                         listItem = child;\r
388                                                         listItemAttrs = listItem.attributes;\r
389                                                         listType = listItem.attributes[ 'cke:listtype' ];\r
390 \r
391                                                         // List item indent level might come from a real list indentation or\r
392                                                         // been resolved from a pseudo list item's margin value, even get\r
393                                                         // no indentation at all.\r
394                                                         listItemIndent = parseInt( listItemAttrs[ 'cke:indent' ], 10 )\r
395                                                                                                         || listBaseIndent && ( Math.ceil( listItemAttrs[ 'cke:margin' ] / listBaseIndent ) )\r
396                                                                                                         || 1;\r
397 \r
398                                                         // Ignore the 'list-style-type' attribute if it's matched with\r
399                                                         // the list root element's default style type.\r
400                                                         listItemAttrs.style && ( listItemAttrs.style =\r
401                                                                 CKEDITOR.plugins.pastefromword.filters.stylesFilter(\r
402                                                                         [\r
403                                                                                 [ 'list-style-type', listType == 'ol' ? 'decimal' : 'disc' ]\r
404                                                                         ] )( listItemAttrs.style )\r
405                                                                         || '' );\r
406 \r
407                                                         if ( !list )\r
408                                                         {\r
409                                                                 list = new CKEDITOR.htmlParser.element( listType );\r
410                                                                 list.add( listItem );\r
411                                                                 children[ i ] = list;\r
412                                                         }\r
413                                                         else\r
414                                                         {\r
415                                                                 if ( listItemIndent > indent )\r
416                                                                 {\r
417                                                                         list = new CKEDITOR.htmlParser.element( listType );\r
418                                                                         list.add( listItem );\r
419                                                                         lastListItem.add( list );\r
420                                                                 }\r
421                                                                 else if ( listItemIndent < indent )\r
422                                                                 {\r
423                                                                         // There might be a negative gap between two list levels. (#4944)\r
424                                                                         var diff = indent - listItemIndent,\r
425                                                                                 parent;\r
426                                                                         while ( diff-- && ( parent = list.parent ) )\r
427                                                                                 list = parent.parent;\r
428 \r
429                                                                         list.add( listItem );\r
430                                                                 }\r
431                                                                 else\r
432                                                                         list.add( listItem );\r
433 \r
434                                                                 children.splice( i--, 1 );\r
435                                                         }\r
436 \r
437                                                         lastListItem = listItem;\r
438                                                         indent = listItemIndent;\r
439                                                 }\r
440                                                 else\r
441                                                         list = null;\r
442                                         }\r
443 \r
444                                         listBaseIndent = 0;\r
445                                 },\r
446 \r
447                                 /**\r
448                                  * A simple filter which always rejecting.\r
449                                  */\r
450                                 falsyFilter : function( value )\r
451                                 {\r
452                                         return false;\r
453                                 },\r
454 \r
455                                 /**\r
456                                  * A filter dedicated on the 'style' attribute filtering, e.g. dropping/replacing style properties.\r
457                                  * @param styles {Array} in form of [ styleNameRegexp, styleValueRegexp,\r
458                                  *  newStyleValue/newStyleGenerator, newStyleName ] where only the first\r
459                                  *  parameter is mandatory.\r
460                                  * @param whitelist {Boolean} Whether the {@param styles} will be considered as a white-list.\r
461                                  */\r
462                                 stylesFilter : function( styles, whitelist )\r
463                                 {\r
464                                         return function( styleText, element )\r
465                                         {\r
466                                                  var rules = [];\r
467                                                 // html-encoded quote might be introduced by 'font-family'\r
468                                                 // from MS-Word which confused the following regexp. e.g.\r
469                                                 //'font-family: &quot;Lucida, Console&quot;'\r
470                                                  styleText\r
471                                                         .replace( /&quot;/g, '"' )\r
472                                                         .replace( /\s*([^ :;]+)\s*:\s*([^;]+)\s*(?=;|$)/g,\r
473                                                                  function( match, name, value )\r
474                                                                  {\r
475                                                                          name = name.toLowerCase();\r
476                                                                          name == 'font-family' && ( value = value.replace( /["']/g, '' ) );\r
477 \r
478                                                                          var namePattern,\r
479                                                                                  valuePattern,\r
480                                                                                  newValue,\r
481                                                                                  newName;\r
482                                                                          for ( var i = 0 ; i < styles.length; i++ )\r
483                                                                          {\r
484                                                                                 if ( styles[ i ] )\r
485                                                                                 {\r
486                                                                                         namePattern = styles[ i ][ 0 ];\r
487                                                                                         valuePattern = styles[ i ][ 1 ];\r
488                                                                                         newValue = styles[ i ][ 2 ];\r
489                                                                                         newName = styles[ i ][ 3 ];\r
490 \r
491                                                                                         if ( name.match( namePattern )\r
492                                                                                                  && ( !valuePattern || value.match( valuePattern ) ) )\r
493                                                                                         {\r
494                                                                                                 name = newName || name;\r
495                                                                                                 whitelist && ( newValue = newValue || value );\r
496 \r
497                                                                                                 if ( typeof newValue == 'function' )\r
498                                                                                                         newValue = newValue( value, element, name );\r
499 \r
500                                                                                                 // Return an couple indicate both name and value\r
501                                                                                                 // changed.\r
502                                                                                                 if ( newValue && newValue.push )\r
503                                                                                                         name = newValue[ 0 ], newValue = newValue[ 1 ];\r
504 \r
505                                                                                                 if ( typeof newValue == 'string' )\r
506                                                                                                         rules.push( [ name, newValue ] );\r
507                                                                                                 return;\r
508                                                                                         }\r
509                                                                                 }\r
510                                                                          }\r
511 \r
512                                                                          !whitelist && rules.push( [ name, value ] );\r
513 \r
514                                                                  });\r
515 \r
516                                                 for ( var i = 0 ; i < rules.length ; i++ )\r
517                                                          rules[ i ] = rules[ i ].join( ':' );\r
518                                                 return rules.length ?\r
519                                                          ( rules.join( ';' ) + ';' ) : false;\r
520                                          };\r
521                                 },\r
522 \r
523                                 /**\r
524                                  * Migrate the element by decorate styles on it.\r
525                                  * @param styleDefiniton\r
526                                  * @param variables\r
527                                  */\r
528                                 elementMigrateFilter : function ( styleDefiniton, variables )\r
529                                 {\r
530                                         return function( element )\r
531                                                 {\r
532                                                         var styleDef =\r
533                                                                         variables ?\r
534                                                                                 new CKEDITOR.style( styleDefiniton, variables )._.definition\r
535                                                                                 : styleDefiniton;\r
536                                                         element.name = styleDef.element;\r
537                                                         CKEDITOR.tools.extend( element.attributes, CKEDITOR.tools.clone( styleDef.attributes ) );\r
538                                                         element.addStyle( CKEDITOR.style.getStyleText( styleDef ) );\r
539                                                 };\r
540                                 },\r
541 \r
542                                 /**\r
543                                  * Migrate styles by creating a new nested stylish element.\r
544                                  * @param styleDefinition\r
545                                  */\r
546                                 styleMigrateFilter : function( styleDefinition, variableName )\r
547                                 {\r
548 \r
549                                         var elementMigrateFilter = this.elementMigrateFilter;\r
550                                         return function( value, element )\r
551                                         {\r
552                                                 // Build an stylish element first.\r
553                                                 var styleElement = new CKEDITOR.htmlParser.element( null ),\r
554                                                         variables = {};\r
555 \r
556                                                 variables[ variableName ] = value;\r
557                                                 elementMigrateFilter( styleDefinition, variables )( styleElement );\r
558                                                 // Place the new element inside the existing span.\r
559                                                 styleElement.children = element.children;\r
560                                                 element.children = [ styleElement ];\r
561                                         };\r
562                                 },\r
563 \r
564                                 /**\r
565                                  * A filter which remove cke-namespaced-attribute on\r
566                                  * all none-cke-namespaced elements.\r
567                                  * @param value\r
568                                  * @param element\r
569                                  */\r
570                                 bogusAttrFilter : function( value, element )\r
571                                 {\r
572                                         if ( element.name.indexOf( 'cke:' ) == -1 )\r
573                                                 return false;\r
574                                 },\r
575 \r
576                                 /**\r
577                                  * A filter which will be used to apply inline css style according the stylesheet\r
578                                  * definition rules, is generated lazily when filtering.\r
579                                  */\r
580                                 applyStyleFilter : null\r
581 \r
582                         },\r
583 \r
584                 getRules : function( editor )\r
585                 {\r
586                         var dtd = CKEDITOR.dtd,\r
587                                 blockLike = CKEDITOR.tools.extend( {}, dtd.$block, dtd.$listItem, dtd.$tableContent ),\r
588                                 config = editor.config,\r
589                                 filters = this.filters,\r
590                                 falsyFilter = filters.falsyFilter,\r
591                                 stylesFilter = filters.stylesFilter,\r
592                                 elementMigrateFilter = filters.elementMigrateFilter,\r
593                                 styleMigrateFilter = CKEDITOR.tools.bind( this.filters.styleMigrateFilter, this.filters ),\r
594                                 createListBulletMarker = this.utils.createListBulletMarker,\r
595                                 flattenList = filters.flattenList,\r
596                                 assembleList = filters.assembleList,\r
597                                 isListBulletIndicator = this.utils.isListBulletIndicator,\r
598                                 containsNothingButSpaces = this.utils.isContainingOnlySpaces,\r
599                                 resolveListItem = this.utils.resolveList,\r
600                                 convertToPx = this.utils.convertToPx,\r
601                                 getStyleComponents = this.utils.getStyleComponents,\r
602                                 listDtdParents = this.utils.listDtdParents,\r
603                                 removeFontStyles = config.pasteFromWordRemoveFontStyles !== false,\r
604                                 removeStyles = config.pasteFromWordRemoveStyles !== false;\r
605 \r
606                         return {\r
607 \r
608                                 elementNames :\r
609                                 [\r
610                                         // Remove script, meta and link elements.\r
611                                         [ ( /meta|link|script/ ), '' ]\r
612                                 ],\r
613 \r
614                                 root : function( element )\r
615                                 {\r
616                                         element.filterChildren();\r
617                                         assembleList( element );\r
618                                 },\r
619 \r
620                                 elements :\r
621                                 {\r
622                                         '^' : function( element )\r
623                                         {\r
624                                                 // Transform CSS style declaration to inline style.\r
625                                                 var applyStyleFilter;\r
626                                                 if ( CKEDITOR.env.gecko && ( applyStyleFilter = filters.applyStyleFilter ) )\r
627                                                         applyStyleFilter( element );\r
628                                         },\r
629 \r
630                                         $ : function( element )\r
631                                         {\r
632                                                 var tagName = element.name || '',\r
633                                                         attrs = element.attributes;\r
634 \r
635                                                 // Convert length unit of width/height on blocks to\r
636                                                 // a more editor-friendly way (px).\r
637                                                 if ( tagName in blockLike\r
638                                                         && attrs.style )\r
639                                                 {\r
640                                                         attrs.style = stylesFilter(\r
641                                                                                 [ [ ( /^(:?width|height)$/ ), null, convertToPx ] ] )( attrs.style ) || '';\r
642                                                 }\r
643 \r
644                                                 // Processing headings.\r
645                                                 if ( tagName.match( /h\d/ ) )\r
646                                                 {\r
647                                                         element.filterChildren();\r
648                                                         // Is the heading actually a list item?\r
649                                                         if ( resolveListItem( element ) )\r
650                                                                 return;\r
651 \r
652                                                         // Adapt heading styles to editor's convention.\r
653                                                         elementMigrateFilter( config[ 'format_' + tagName ] )( element );\r
654                                                 }\r
655                                                 // Remove inline elements which contain only empty spaces.\r
656                                                 else if ( tagName in dtd.$inline )\r
657                                                 {\r
658                                                         element.filterChildren();\r
659                                                         if ( containsNothingButSpaces( element ) )\r
660                                                                 delete element.name;\r
661                                                 }\r
662                                                 // Remove element with ms-office namespace,\r
663                                                 // with it's content preserved, e.g. 'o:p'.\r
664                                                 else if ( tagName.indexOf( ':' ) != -1\r
665                                                                  && tagName.indexOf( 'cke' ) == -1 )\r
666                                                 {\r
667                                                         element.filterChildren();\r
668 \r
669                                                         // Restore image real link from vml.\r
670                                                         if ( tagName == 'v:imagedata' )\r
671                                                         {\r
672                                                                 var href = element.attributes[ 'o:href' ];\r
673                                                                 if ( href )\r
674                                                                         element.attributes.src = href;\r
675                                                                 element.name = 'img';\r
676                                                                 return;\r
677                                                         }\r
678                                                         delete element.name;\r
679                                                 }\r
680 \r
681                                                 // Assembling list items into a whole list.\r
682                                                 if ( tagName in listDtdParents )\r
683                                                 {\r
684                                                         element.filterChildren();\r
685                                                         assembleList( element );\r
686                                                 }\r
687                                         },\r
688 \r
689                                         // We'll drop any style sheet, but Firefox conclude\r
690                                         // certain styles in a single style element, which are\r
691                                         // required to be changed into inline ones.\r
692                                         'style' : function( element )\r
693                                         {\r
694                                                 if ( CKEDITOR.env.gecko )\r
695                                                 {\r
696                                                         // Grab only the style definition section.\r
697                                                         var styleDefSection = element.onlyChild().value.match( /\/\* Style Definitions \*\/([\s\S]*?)\/\*/ ),\r
698                                                                 styleDefText = styleDefSection && styleDefSection[ 1 ],\r
699                                                                 rules = {}; // Storing the parsed result.\r
700 \r
701                                                         if ( styleDefText )\r
702                                                         {\r
703                                                                 styleDefText\r
704                                                                         // Remove line-breaks.\r
705                                                                         .replace(/[\n\r]/g,'')\r
706                                                                         // Extract selectors and style properties.\r
707                                                                         .replace( /(.+?)\{(.+?)\}/g,\r
708                                                                                 function( rule, selectors, styleBlock )\r
709                                                                                 {\r
710                                                                                         selectors = selectors.split( ',' );\r
711                                                                                         var length = selectors.length, selector;\r
712                                                                                         for ( var i = 0; i < length; i++ )\r
713                                                                                         {\r
714                                                                                                 // Assume MS-Word mostly generate only simple\r
715                                                                                                 // selector( [Type selector][Class selector]).\r
716                                                                                                 CKEDITOR.tools.trim( selectors[ i ] )\r
717                                                                                                                           .replace( /^(\w+)(\.[\w-]+)?$/g,\r
718                                                                                                 function( match, tagName, className )\r
719                                                                                                 {\r
720                                                                                                         tagName = tagName || '*';\r
721                                                                                                         className = className.substring( 1, className.length );\r
722 \r
723                                                                                                         // Reject MS-Word Normal styles.\r
724                                                                                                         if ( className.match( /MsoNormal/ ) )\r
725                                                                                                                 return;\r
726 \r
727                                                                                                         if ( !rules[ tagName ] )\r
728                                                                                                                 rules[ tagName ] = {};\r
729                                                                                                         if ( className )\r
730                                                                                                                 rules[ tagName ][ className ] = styleBlock;\r
731                                                                                                         else\r
732                                                                                                                 rules[ tagName ] = styleBlock;\r
733                                                                                                 } );\r
734                                                                                         }\r
735                                                                                 });\r
736 \r
737                                                                 filters.applyStyleFilter = function( element )\r
738                                                                 {\r
739                                                                         var name = rules[ '*' ] ? '*' : element.name,\r
740                                                                                 className = element.attributes && element.attributes[ 'class' ],\r
741                                                                                 style;\r
742                                                                         if ( name in rules )\r
743                                                                         {\r
744                                                                                 style = rules[ name ];\r
745                                                                                 if ( typeof style == 'object' )\r
746                                                                                         style = style[ className ];\r
747                                                                                 // Maintain style rules priorities.\r
748                                                                                 style && element.addStyle( style, true );\r
749                                                                         }\r
750                                                                 };\r
751                                                         }\r
752                                                 }\r
753                                                 return false;\r
754                                         },\r
755 \r
756                                         'p' : function( element )\r
757                                         {\r
758                                                 element.filterChildren();\r
759 \r
760                                                 // Is the paragraph actually a list item?\r
761                                                 if ( resolveListItem( element ) )\r
762                                                         return;\r
763 \r
764                                                 // Adapt paragraph formatting to editor's convention\r
765                                                 // according to enter-mode.\r
766                                                 if ( config.enterMode == CKEDITOR.ENTER_BR )\r
767                                                 {\r
768                                                         // We suffer from attribute/style lost in this situation.\r
769                                                         delete element.name;\r
770                                                         element.add( new CKEDITOR.htmlParser.element( 'br' ) );\r
771                                                 }\r
772                                                 else\r
773                                                         elementMigrateFilter( config[ 'format_' + ( config.enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) ] )( element );\r
774                                         },\r
775 \r
776                                         'div' : function( element )\r
777                                         {\r
778                                                 // Aligned table with no text surrounded is represented by a wrapper div, from which\r
779                                                 // table cells inherit as text-align styles, which is wrong.\r
780                                                 // Instead we use a clear-float div after the table to properly achieve the same layout.\r
781                                                 var singleChild = element.onlyChild();\r
782                                                 if ( singleChild && singleChild.name == 'table' )\r
783                                                 {\r
784                                                         var attrs = element.attributes;\r
785                                                         singleChild.attributes = CKEDITOR.tools.extend( singleChild.attributes, attrs );\r
786                                                         attrs.style && singleChild.addStyle( attrs.style );\r
787 \r
788                                                         var clearFloatDiv = new CKEDITOR.htmlParser.element( 'div' );\r
789                                                         clearFloatDiv.addStyle( 'clear' ,'both' );\r
790                                                         element.add( clearFloatDiv );\r
791                                                         delete element.name;\r
792                                                 }\r
793                                         },\r
794 \r
795                                         'td' : function ( element )\r
796                                         {\r
797                                                 // 'td' in 'thead' is actually <th>.\r
798                                                 if ( element.getAncestor( 'thead') )\r
799                                                         element.name = 'th';\r
800                                         },\r
801 \r
802                                         // MS-Word sometimes present list as a mixing of normal list\r
803                                         // and pseudo-list, normalize the previous ones into pseudo form.\r
804                                         'ol' : flattenList,\r
805                                         'ul' : flattenList,\r
806                                         'dl' : flattenList,\r
807 \r
808                                         'font' : function( element )\r
809                                         {\r
810                                                 // IE/Safari: drop the font tag if it comes from list bullet text.\r
811                                                 if ( !CKEDITOR.env.gecko && isListBulletIndicator( element.parent ) )\r
812                                                 {\r
813                                                         delete element.name;\r
814                                                         return;\r
815                                                 }\r
816 \r
817                                                 element.filterChildren();\r
818 \r
819                                                 var attrs = element.attributes,\r
820                                                         styleText = attrs.style,\r
821                                                         parent = element.parent;\r
822 \r
823                                                 if ( 'font' == parent.name )     // Merge nested <font> tags.\r
824                                                 {\r
825                                                         CKEDITOR.tools.extend( parent.attributes,\r
826                                                                         element.attributes );\r
827                                                         styleText && parent.addStyle( styleText );\r
828                                                         delete element.name;\r
829                                                 }\r
830                                                 // Convert the merged into a span with all attributes preserved.\r
831                                                 else\r
832                                                 {\r
833                                                         styleText = styleText || '';\r
834                                                         // IE's having those deprecated attributes, normalize them.\r
835                                                         if ( attrs.color )\r
836                                                         {\r
837                                                                 attrs.color != '#000000' && ( styleText += 'color:' + attrs.color + ';' );\r
838                                                                 delete attrs.color;\r
839                                                         }\r
840                                                         if ( attrs.face )\r
841                                                         {\r
842                                                                 styleText += 'font-family:' + attrs.face + ';';\r
843                                                                 delete attrs.face;\r
844                                                         }\r
845                                                         // TODO: Mapping size in ranges of xx-small,\r
846                                                         // x-small, small, medium, large, x-large, xx-large.\r
847                                                         if ( attrs.size )\r
848                                                         {\r
849                                                                 styleText += 'font-size:' +\r
850                                                                              ( attrs.size > 3 ? 'large'\r
851                                                                                              : ( attrs.size < 3 ? 'small' : 'medium' ) ) + ';';\r
852                                                                 delete attrs.size;\r
853                                                         }\r
854 \r
855                                                         element.name = 'span';\r
856                                                         element.addStyle( styleText );\r
857                                                 }\r
858                                         },\r
859 \r
860                                         'span' : function( element )\r
861                                         {\r
862                                                 // IE/Safari: remove the span if it comes from list bullet text.\r
863                                                 if ( !CKEDITOR.env.gecko && isListBulletIndicator( element.parent ) )\r
864                                                         return false;\r
865 \r
866                                                 element.filterChildren();\r
867                                                 if ( containsNothingButSpaces( element ) )\r
868                                                 {\r
869                                                         delete element.name;\r
870                                                         return null;\r
871                                                 }\r
872 \r
873                                                 // For IE/Safari: List item bullet type is supposed to be indicated by\r
874                                                 // the text of a span with style 'mso-list : Ignore' or an image.\r
875                                                 if ( !CKEDITOR.env.gecko && isListBulletIndicator( element ) )\r
876                                                 {\r
877                                                         var listSymbolNode = element.firstChild( function( node )\r
878                                                         {\r
879                                                                 return node.value || node.name == 'img';\r
880                                                         });\r
881 \r
882                                                         var listSymbol =  listSymbolNode && ( listSymbolNode.value || 'l.' ),\r
883                                                                 listType = listSymbol.match( /^([^\s]+?)([.)]?)$/ );\r
884                                                         return createListBulletMarker( listType, listSymbol );\r
885                                                 }\r
886 \r
887                                                 // Update the src attribute of image element with href.\r
888                                                 var children = element.children,\r
889                                                         attrs = element.attributes,\r
890                                                         styleText = attrs && attrs.style,\r
891                                                         firstChild = children && children[ 0 ];\r
892 \r
893                                                 // Assume MS-Word mostly carry font related styles on <span>,\r
894                                                 // adapting them to editor's convention.\r
895                                                 if ( styleText )\r
896                                                 {\r
897                                                         attrs.style = stylesFilter(\r
898                                                                         [\r
899                                                                                 // Drop 'inline-height' style which make lines overlapping.\r
900                                                                                 [ 'line-height' ],\r
901                                                                                 [ ( /^font-family$/ ), null, !removeFontStyles ? styleMigrateFilter( config[ 'font_style' ], 'family' ) : null ] ,\r
902                                                                                 [ ( /^font-size$/ ), null, !removeFontStyles ? styleMigrateFilter( config[ 'fontSize_style' ], 'size' ) : null ] ,\r
903                                                                                 [ ( /^color$/ ), null, !removeFontStyles ? styleMigrateFilter( config[ 'colorButton_foreStyle' ], 'color' ) : null ] ,\r
904                                                                                 [ ( /^background-color$/ ), null, !removeFontStyles ? styleMigrateFilter( config[ 'colorButton_backStyle' ], 'color' ) : null ]\r
905                                                                         ] )( styleText, element ) || '';\r
906                                                 }\r
907 \r
908                                                 return null;\r
909                                         },\r
910 \r
911                                         // Migrate basic style formats to editor configured ones.\r
912                                         'b' : elementMigrateFilter( config[ 'coreStyles_bold' ] ),\r
913                                         'i' : elementMigrateFilter( config[ 'coreStyles_italic' ] ),\r
914                                         'u' : elementMigrateFilter( config[ 'coreStyles_underline' ] ),\r
915                                         's' : elementMigrateFilter( config[ 'coreStyles_strike' ] ),\r
916                                         'sup' : elementMigrateFilter( config[ 'coreStyles_superscript' ] ),\r
917                                         'sub' : elementMigrateFilter( config[ 'coreStyles_subscript' ] ),\r
918                                         // Editor doesn't support anchor with content currently (#3582),\r
919                                         // drop such anchors with content preserved.\r
920                                         'a' : function( element )\r
921                                         {\r
922                                                 var attrs = element.attributes;\r
923                                                 if ( attrs && !attrs.href && attrs.name )\r
924                                                         delete element.name;\r
925                                         },\r
926                                         'cke:listbullet' : function( element )\r
927                                         {\r
928                                                 if ( element.getAncestor( /h\d/ ) && !config.pasteFromWordNumberedHeadingToList )\r
929                                                         delete element.name;\r
930                                                 }\r
931                                 },\r
932 \r
933                                 attributeNames :\r
934                                 [\r
935                                         // Remove onmouseover and onmouseout events (from MS Word comments effect)\r
936                                         [ ( /^onmouse(:?out|over)/ ), '' ],\r
937                                         // Onload on image element.\r
938                                         [ ( /^onload$/ ), '' ],\r
939                                         // Remove office and vml attribute from elements.\r
940                                         [ ( /(?:v|o):\w+/ ), '' ],\r
941                                         // Remove lang/language attributes.\r
942                                         [ ( /^lang/ ), '' ]\r
943                                 ],\r
944 \r
945                                 attributes :\r
946                                 {\r
947                                         'style' : stylesFilter(\r
948                                         removeStyles ?\r
949                                         // Provide a white-list of styles that we preserve, those should\r
950                                         // be the ones that could later be altered with editor tools.\r
951                                         [\r
952                                                 // Preserve margin-left/right which used as default indent style in the editor.\r
953                                                 [ ( /^margin$|^margin-(?!bottom|top)/ ), null, function( value, element, name )\r
954                                                         {\r
955                                                                 if ( element.name in { p : 1, div : 1 } )\r
956                                                                 {\r
957                                                                         var indentStyleName = config.contentsLangDirection == 'ltr' ?\r
958                                                                                         'margin-left' : 'margin-right';\r
959 \r
960                                                                         // Extract component value from 'margin' shorthand.\r
961                                                                         if ( name == 'margin' )\r
962                                                                         {\r
963                                                                                 value = getStyleComponents( name, value,\r
964                                                                                                 [ indentStyleName ] )[ indentStyleName ];\r
965                                                                         }\r
966                                                                         else if ( name != indentStyleName )\r
967                                                                                 return null;\r
968 \r
969                                                                         if ( value && !emptyMarginRegex.test( value ) )\r
970                                                                                 return [ indentStyleName, value ];\r
971                                                                 }\r
972 \r
973                                                                 return null;\r
974                                                         } ],\r
975 \r
976                                                 // Preserve clear float style.\r
977                                                 [ ( /^clear$/ ) ],\r
978 \r
979                                                 [ ( /^border.*|margin.*|vertical-align|float$/ ), null,\r
980                                                         function( value, element )\r
981                                                         {\r
982                                                                 if ( element.name == 'img' )\r
983                                                                         return value;\r
984                                                         } ],\r
985 \r
986                                                 [ (/^width|height$/ ), null,\r
987                                                         function( value, element )\r
988                                                         {\r
989                                                                 if ( element.name in { table : 1, td : 1, th : 1, img : 1 } )\r
990                                                                         return value;\r
991                                                         } ]\r
992                                         ] :\r
993                                         // Otherwise provide a black-list of styles that we remove.\r
994                                         [\r
995                                                 [ ( /^mso-/ ) ],\r
996                                                 // Fixing color values.\r
997                                                 [ ( /-color$/ ), null, function( value )\r
998                                                 {\r
999                                                         if ( value == 'transparent' )\r
1000                                                                 return false;\r
1001                                                         if ( CKEDITOR.env.gecko )\r
1002                                                                 return value.replace( /-moz-use-text-color/g, 'transparent' );\r
1003                                                 } ],\r
1004                                                 // Remove empty margin values, e.g. 0.00001pt 0em 0pt\r
1005                                                 [ ( /^margin$/ ), emptyMarginRegex ],\r
1006                                                 [ 'text-indent', '0cm' ],\r
1007                                                 [ 'page-break-before' ],\r
1008                                                 [ 'tab-stops' ],\r
1009                                                 [ 'display', 'none' ],\r
1010                                                 removeFontStyles ? [ ( /font-?/ ) ] : null\r
1011                                         ], removeStyles ),\r
1012 \r
1013                                         // Prefer width styles over 'width' attributes.\r
1014                                         'width' : function( value, element )\r
1015                                         {\r
1016                                                 if ( element.name in dtd.$tableContent )\r
1017                                                         return false;\r
1018                                         },\r
1019                                         // Prefer border styles over table 'border' attributes.\r
1020                                         'border' : function( value, element )\r
1021                                         {\r
1022                                                 if ( element.name in dtd.$tableContent )\r
1023                                                         return false;\r
1024                                         },\r
1025 \r
1026                                         // Only Firefox carry style sheet from MS-Word, which\r
1027                                         // will be applied by us manually. For other browsers\r
1028                                         // the css className is useless.\r
1029                                         'class' : falsyFilter,\r
1030 \r
1031                                         // MS-Word always generate 'background-color' along with 'bgcolor',\r
1032                                         // simply drop the deprecated attributes.\r
1033                                         'bgcolor' : falsyFilter,\r
1034 \r
1035                                         // Deprecate 'valign' attribute in favor of 'vertical-align'.\r
1036                                         'valign' : removeStyles ? falsyFilter : function( value, element )\r
1037                                         {\r
1038                                                 element.addStyle( 'vertical-align', value );\r
1039                                                 return false;\r
1040                                         }\r
1041                                 },\r
1042 \r
1043                                 // Fore none-IE, some useful data might be buried under these IE-conditional\r
1044                                 // comments where RegExp were the right approach to dig them out where usual approach\r
1045                                 // is transform it into a fake element node which hold the desired data.\r
1046                                 comment :\r
1047                                         !CKEDITOR.env.ie ?\r
1048                                                 function( value, node )\r
1049                                                 {\r
1050                                                         var imageInfo = value.match( /<img.*?>/ ),\r
1051                                                                 listInfo = value.match( /^\[if !supportLists\]([\s\S]*?)\[endif\]$/ );\r
1052 \r
1053                                                         // Seek for list bullet indicator.\r
1054                                                         if ( listInfo )\r
1055                                                         {\r
1056                                                                 // Bullet symbol could be either text or an image.\r
1057                                                                 var listSymbol = listInfo[ 1 ] || ( imageInfo && 'l.' ),\r
1058                                                                         listType = listSymbol && listSymbol.match( />([^\s]+?)([.)]?)</ );\r
1059                                                                 return createListBulletMarker( listType, listSymbol );\r
1060                                                         }\r
1061 \r
1062                                                         // Reveal the <img> element in conditional comments for Firefox.\r
1063                                                         if ( CKEDITOR.env.gecko && imageInfo )\r
1064                                                         {\r
1065                                                                 var img = CKEDITOR.htmlParser.fragment.fromHtml( imageInfo[ 0 ] ).children[ 0 ],\r
1066                                                                         previousComment = node.previous,\r
1067                                                                         // Try to dig the real image link from vml markup from previous comment text.\r
1068                                                                         imgSrcInfo = previousComment && previousComment.value.match( /<v:imagedata[^>]*o:href=['"](.*?)['"]/ ),\r
1069                                                                         imgSrc = imgSrcInfo && imgSrcInfo[ 1 ];\r
1070 \r
1071                                                                 // Is there a real 'src' url to be used?\r
1072                                                                 imgSrc && ( img.attributes.src = imgSrc );\r
1073                                                                 return img;\r
1074                                                         }\r
1075 \r
1076                                                         return false;\r
1077                                                 }\r
1078                                         : falsyFilter\r
1079                         };\r
1080                 }\r
1081         };\r
1082 \r
1083         // The paste processor here is just a reduced copy of html data processor.\r
1084         var pasteProcessor = function()\r
1085         {\r
1086                 this.dataFilter = new CKEDITOR.htmlParser.filter();\r
1087         };\r
1088 \r
1089         pasteProcessor.prototype =\r
1090         {\r
1091                 toHtml : function( data )\r
1092                 {\r
1093                         var fragment = CKEDITOR.htmlParser.fragment.fromHtml( data, false ),\r
1094                                 writer = new CKEDITOR.htmlParser.basicWriter();\r
1095 \r
1096                         fragment.writeHtml( writer, this.dataFilter );\r
1097                         return writer.getHtml( true );\r
1098                 }\r
1099         };\r
1100 \r
1101         CKEDITOR.cleanWord = function( data, editor )\r
1102         {\r
1103                 // Firefox will be confused by those downlevel-revealed IE conditional\r
1104                 // comments, fixing them first( convert it to upperlevel-revealed one ).\r
1105                 // e.g. <![if !vml]>...<![endif]>\r
1106                 if ( CKEDITOR.env.gecko )\r
1107                         data = data.replace( /(<!--\[if[^<]*?\])-->([\S\s]*?)<!--(\[endif\]-->)/gi, '$1$2$3' );\r
1108 \r
1109                 var dataProcessor = new pasteProcessor(),\r
1110                         dataFilter = dataProcessor.dataFilter;\r
1111 \r
1112                 // These rules will have higher priorities than default ones.\r
1113                 dataFilter.addRules( CKEDITOR.plugins.pastefromword.getRules( editor ) );\r
1114 \r
1115                 // Allow extending data filter rules.\r
1116                 editor.fire( 'beforeCleanWord', { filter : dataFilter } );\r
1117 \r
1118                 try\r
1119                 {\r
1120                         data = dataProcessor.toHtml( data, false );\r
1121                 }\r
1122                 catch ( e )\r
1123                 {\r
1124                         alert( editor.lang.pastefromword.error );\r
1125                 }\r
1126 \r
1127                 /* Below post processing those things that are unable to delivered by filter rules. */\r
1128 \r
1129                 // Remove 'cke' namespaced attribute used in filter rules as marker.\r
1130                 data = data.replace( /cke:.*?".*?"/g, '' );\r
1131 \r
1132                 // Remove empty style attribute.\r
1133                 data = data.replace( /style=""/g, '' );\r
1134 \r
1135                 // Remove the dummy spans ( having no inline style ).\r
1136                 data = data.replace( /<span>/g, '' );\r
1137 \r
1138                 return data;\r
1139         };\r
1140 })();\r
1141 \r
1142 /**\r
1143  * Whether to ignore all font related formatting styles, including:\r
1144  * <ul> <li>font size;</li>\r
1145  *              <li>font family;</li>\r
1146  *              <li>font foreground/background color.</li></ul>\r
1147  * @name CKEDITOR.config.pasteFromWordRemoveFontStyles\r
1148  * @since 3.1\r
1149  * @type Boolean\r
1150  * @default true\r
1151  * @example\r
1152  * config.pasteFromWordRemoveFontStyles = false;\r
1153  */\r
1154 \r
1155 /**\r
1156  * Whether to transform MS Word outline numbered headings into lists.\r
1157  * @name CKEDITOR.config.pasteFromWordNumberedHeadingToList\r
1158  * @since 3.1\r
1159  * @type Boolean\r
1160  * @default false\r
1161  * @example\r
1162  * config.pasteFromWordNumberedHeadingToList = true;\r
1163  */\r
1164 \r
1165 /**\r
1166  * Whether to remove element styles that can't be managed with the editor. Note\r
1167  * that this doesn't handle the font specific styles, which depends on the\r
1168  * {@link CKEDITOR.config.pasteFromWordRemoveFontStyles} setting instead.\r
1169  * @name CKEDITOR.config.pasteFromWordRemoveStyles\r
1170  * @since 3.1\r
1171  * @type Boolean\r
1172  * @default true\r
1173  * @example\r
1174  * config.pasteFromWordRemoveStyles = false;\r
1175  */\r