+/*\r
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
+For licensing, see LICENSE.html or http://ckeditor.com/license\r
+*/\r
+\r
+(function()\r
+{\r
+ var fragmentPrototype = CKEDITOR.htmlParser.fragment.prototype,\r
+ elementPrototype = CKEDITOR.htmlParser.element.prototype;\r
+\r
+ fragmentPrototype.onlyChild = elementPrototype.onlyChild = function()\r
+ {\r
+ var children = this.children,\r
+ count = children.length,\r
+ firstChild = ( count == 1 ) && children[ 0 ];\r
+ return firstChild || null;\r
+ };\r
+\r
+ elementPrototype.removeAnyChildWithName = function( tagName )\r
+ {\r
+ var children = this.children,\r
+ childs = [],\r
+ child;\r
+\r
+ for ( var i = 0; i < children.length; i++ )\r
+ {\r
+ child = children[ i ];\r
+ if ( !child.name )\r
+ continue;\r
+\r
+ if ( child.name == tagName )\r
+ {\r
+ childs.push( child );\r
+ children.splice( i--, 1 );\r
+ }\r
+ childs = childs.concat( child.removeAnyChildWithName( tagName ) );\r
+ }\r
+ return childs;\r
+ };\r
+\r
+ elementPrototype.getAncestor = function( tagNameRegex )\r
+ {\r
+ var parent = this.parent;\r
+ while ( parent && !( parent.name && parent.name.match( tagNameRegex ) ) )\r
+ parent = parent.parent;\r
+ return parent;\r
+ };\r
+\r
+ fragmentPrototype.firstChild = elementPrototype.firstChild = function( evaluator )\r
+ {\r
+ var child;\r
+\r
+ for ( var i = 0 ; i < this.children.length ; i++ )\r
+ {\r
+ child = this.children[ i ];\r
+ if ( evaluator( child ) )\r
+ return child;\r
+ else if ( child.name )\r
+ {\r
+ child = child.firstChild( evaluator );\r
+ if ( child )\r
+ return child;\r
+ }\r
+ }\r
+\r
+ return null;\r
+ };\r
+\r
+ // Adding a (set) of styles to the element's 'style' attributes.\r
+ elementPrototype.addStyle = function( name, value, isPrepend )\r
+ {\r
+ var styleText, addingStyleText = '';\r
+ // name/value pair.\r
+ if ( typeof value == 'string' )\r
+ addingStyleText += name + ':' + value + ';';\r
+ else\r
+ {\r
+ // style literal.\r
+ if ( typeof name == 'object' )\r
+ {\r
+ for ( var style in name )\r
+ {\r
+ if ( name.hasOwnProperty( style ) )\r
+ addingStyleText += style + ':' + name[ style ] + ';';\r
+ }\r
+ }\r
+ // raw style text form.\r
+ else\r
+ addingStyleText += name;\r
+\r
+ isPrepend = value;\r
+ }\r
+\r
+ if ( !this.attributes )\r
+ this.attributes = {};\r
+\r
+ styleText = this.attributes.style || '';\r
+\r
+ styleText = ( isPrepend ?\r
+ [ addingStyleText, styleText ]\r
+ : [ styleText, addingStyleText ] ).join( ';' );\r
+\r
+ this.attributes.style = styleText.replace( /^;|;(?=;)/, '' );\r
+ };\r
+\r
+ /**\r
+ * Return the DTD-valid parent tag names of the specified one.\r
+ * @param tagName\r
+ */\r
+ CKEDITOR.dtd.parentOf = function( tagName )\r
+ {\r
+ var result = {};\r
+ for ( var tag in this )\r
+ {\r
+ if ( tag.indexOf( '$' ) == -1 && this[ tag ][ tagName ] )\r
+ result[ tag ] = 1;\r
+ }\r
+ return result;\r
+ };\r
+\r
+ // 1. move consistent list item styles up to list root.\r
+ // 2. clear out unnecessary list item numbering.\r
+ function postProcessList( list )\r
+ {\r
+ var children = list.children,\r
+ child,\r
+ attrs,\r
+ count = list.children.length,\r
+ match,\r
+ mergeStyle,\r
+ styleTypeRegexp = /list-style-type:(.*?)(?:;|$)/,\r
+ stylesFilter = CKEDITOR.plugins.pastefromword.filters.stylesFilter;\r
+\r
+ attrs = list.attributes;\r
+ if ( styleTypeRegexp.exec( attrs.style ) )\r
+ return;\r
+\r
+ for ( var i = 0; i < count; i++ )\r
+ {\r
+ child = children[ i ];\r
+\r
+ if ( child.attributes.value && Number( child.attributes.value ) == i + 1 )\r
+ delete child.attributes.value;\r
+\r
+ match = styleTypeRegexp.exec( child.attributes.style );\r
+\r
+ if ( match )\r
+ {\r
+ if ( match[ 1 ] == mergeStyle || !mergeStyle )\r
+ mergeStyle = match[ 1 ];\r
+ else\r
+ {\r
+ mergeStyle = null;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+\r
+ if ( mergeStyle )\r
+ {\r
+ for ( i = 0; i < count; i++ )\r
+ {\r
+ attrs = children[ i ].attributes;\r
+ attrs.style && ( attrs.style = stylesFilter( [ [ 'list-style-type'] ] )( attrs.style ) || '' );\r
+ }\r
+\r
+ list.addStyle( 'list-style-type', mergeStyle );\r
+ }\r
+ }\r
+\r
+ 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
+ var emptyMarginRegex = /^(?:\b0[^\s]*\s*){1,4}$/; // e.g. 0px 0pt 0px\r
+ var romanLiternalPattern = '^m{0,4}(cm|cd|d?c{0,3})(xc|xl|l?x{0,3})(ix|iv|v?i{0,3})$',\r
+ lowerRomanLiteralRegex = new RegExp( romanLiternalPattern ),\r
+ upperRomanLiteralRegex = new RegExp( romanLiternalPattern.toUpperCase() );\r
+\r
+ var orderedPatterns = { 'decimal' : /\d+/, 'lower-roman': lowerRomanLiteralRegex, 'upper-roman': upperRomanLiteralRegex, 'lower-alpha' : /^[a-z]+$/, 'upper-alpha': /^[A-Z]+$/ },\r
+ unorderedPatterns = { 'disc' : /[l\u00B7\u2002]/, 'circle' : /[\u006F\u00D8]/,'square' : /[\u006E\u25C6]/},\r
+ listMarkerPatterns = { 'ol' : orderedPatterns, 'ul' : unorderedPatterns },\r
+ romans = [ [1000, 'M'], [900, 'CM'], [500, 'D'], [400, 'CD'], [100, 'C'], [90, 'XC'], [50, 'L'], [40, 'XL'], [10, 'X'], [9, 'IX'], [5, 'V'], [4, 'IV'], [1, 'I'] ],\r
+ alpahbets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";\r
+\r
+ // Convert roman numbering back to decimal.\r
+ function fromRoman( str )\r
+ {\r
+ str = str.toUpperCase();\r
+ var l = romans.length, retVal = 0;\r
+ for ( var i = 0; i < l; ++i )\r
+ {\r
+ for ( var j = romans[i], k = j[1].length; str.substr( 0, k ) == j[1]; str = str.substr( k ) )\r
+ retVal += j[ 0 ];\r
+ }\r
+ return retVal;\r
+ }\r
+\r
+ // Convert alphabet numbering back to decimal.\r
+ function fromAlphabet( str )\r
+ {\r
+ str = str.toUpperCase();\r
+ var l = alpahbets.length, retVal = 1;\r
+ for ( var x = 1; str.length > 0; x *= l )\r
+ {\r
+ retVal += alpahbets.indexOf( str.charAt( str.length - 1 ) ) * x;\r
+ str = str.substr( 0, str.length - 1 );\r
+ }\r
+ return retVal;\r
+ }\r
+\r
+ var listBaseIndent = 0,\r
+ previousListItemMargin = null,\r
+ previousListId;\r
+\r
+ var plugin = ( CKEDITOR.plugins.pastefromword =\r
+ {\r
+ utils :\r
+ {\r
+ // Create a <cke:listbullet> which indicate an list item type.\r
+ createListBulletMarker : function ( bullet, bulletText )\r
+ {\r
+ var marker = new CKEDITOR.htmlParser.element( 'cke:listbullet' );\r
+ marker.attributes = { 'cke:listsymbol' : bullet[ 0 ] };\r
+ marker.add( new CKEDITOR.htmlParser.text( bulletText ) );\r
+ return marker;\r
+ },\r
+\r
+ isListBulletIndicator : function( element )\r
+ {\r
+ var styleText = element.attributes && element.attributes.style;\r
+ if ( /mso-list\s*:\s*Ignore/i.test( styleText ) )\r
+ return true;\r
+ },\r
+\r
+ isContainingOnlySpaces : function( element )\r
+ {\r
+ var text;\r
+ return ( ( text = element.onlyChild() )\r
+ && ( /^(:?\s| )+$/ ).test( text.value ) );\r
+ },\r
+\r
+ resolveList : function( element )\r
+ {\r
+ // <cke:listbullet> indicate a list item.\r
+ var attrs = element.attributes,\r
+ listMarker;\r
+\r
+ if ( ( listMarker = element.removeAnyChildWithName( 'cke:listbullet' ) )\r
+ && listMarker.length\r
+ && ( listMarker = listMarker[ 0 ] ) )\r
+ {\r
+ element.name = 'cke:li';\r
+\r
+ if ( attrs.style )\r
+ {\r
+ attrs.style = plugin.filters.stylesFilter(\r
+ [\r
+ // Text-indent is not representing list item level any more.\r
+ [ 'text-indent' ],\r
+ [ 'line-height' ],\r
+ // First attempt is to resolve indent level from on a constant margin increment.\r
+ [ ( /^margin(:?-left)?$/ ), null, function( margin )\r
+ {\r
+ // Deal with component/short-hand form.\r
+ var values = margin.split( ' ' );\r
+ margin = CKEDITOR.tools.convertToPx( values[ 3 ] || values[ 1 ] || values [ 0 ] );\r
+\r
+ // Figure out the indent unit by checking the first time of incrementation.\r
+ if ( !listBaseIndent && previousListItemMargin !== null && margin > previousListItemMargin )\r
+ listBaseIndent = margin - previousListItemMargin;\r
+\r
+ previousListItemMargin = margin;\r
+\r
+ attrs[ 'cke:indent' ] = listBaseIndent && ( Math.ceil( margin / listBaseIndent ) + 1 ) || 1;\r
+ } ],\r
+ // The best situation: "mso-list:l0 level1 lfo2" tells the belonged list root, list item indentation, etc.\r
+ [ ( /^mso-list$/ ), null, function( val )\r
+ {\r
+ val = val.split( ' ' );\r
+ var listId = Number( val[ 0 ].match( /\d+/ ) ),\r
+ indent = Number( val[ 1 ].match( /\d+/ ) );\r
+\r
+ if ( indent == 1 )\r
+ {\r
+ listId !== previousListId && ( attrs[ 'cke:reset' ] = 1 );\r
+ previousListId = listId;\r
+ }\r
+ attrs[ 'cke:indent' ] = indent;\r
+ } ]\r
+ ] )( attrs.style, element ) || '';\r
+ }\r
+\r
+ // First level list item might be presented without a margin.\r
+\r
+\r
+ // In case all above doesn't apply.\r
+ if ( !attrs[ 'cke:indent' ] )\r
+ {\r
+ previousListItemMargin = 0;\r
+ attrs[ 'cke:indent' ] = 1;\r
+ }\r
+\r
+ // Inherit attributes from bullet.\r
+ CKEDITOR.tools.extend( attrs, listMarker.attributes );\r
+ return true;\r
+ }\r
+ // Current list disconnected.\r
+ else\r
+ previousListId = previousListItemMargin = listBaseIndent = null;\r
+\r
+ return false;\r
+ },\r
+\r
+ // Providing a shorthand style then retrieve one or more style component values.\r
+ getStyleComponents : ( function()\r
+ {\r
+ var calculator = CKEDITOR.dom.element.createFromHtml(\r
+ '<div style="position:absolute;left:-9999px;top:-9999px;"></div>',\r
+ CKEDITOR.document );\r
+ CKEDITOR.document.getBody().append( calculator );\r
+\r
+ return function( name, styleValue, fetchList )\r
+ {\r
+ calculator.setStyle( name, styleValue );\r
+ var styles = {},\r
+ count = fetchList.length;\r
+ for ( var i = 0; i < count; i++ )\r
+ styles[ fetchList[ i ] ] = calculator.getStyle( fetchList[ i ] );\r
+\r
+ return styles;\r
+ };\r
+ } )(),\r
+\r
+ listDtdParents : CKEDITOR.dtd.parentOf( 'ol' )\r
+ },\r
+\r
+ filters :\r
+ {\r
+ // Transform a normal list into flat list items only presentation.\r
+ // E.g. <ul><li>level1<ol><li>level2</li></ol></li> =>\r
+ // <cke:li cke:listtype="ul" cke:indent="1">level1</cke:li>\r
+ // <cke:li cke:listtype="ol" cke:indent="2">level2</cke:li>\r
+ flattenList : function( element, level )\r
+ {\r
+ level = typeof level == 'number' ? level : 1;\r
+\r
+ var attrs = element.attributes,\r
+ listStyleType;\r
+\r
+ // All list items are of the same type.\r
+ switch ( attrs.type )\r
+ {\r
+ case 'a' :\r
+ listStyleType = 'lower-alpha';\r
+ break;\r
+ case '1' :\r
+ listStyleType = 'decimal';\r
+ break;\r
+ // TODO: Support more list style type from MS-Word.\r
+ }\r
+\r
+ var children = element.children,\r
+ child;\r
+\r
+ for ( var i = 0; i < children.length; i++ )\r
+ {\r
+ child = children[ i ];\r
+\r
+ if ( child.name in CKEDITOR.dtd.$listItem )\r
+ {\r
+ var attributes = child.attributes,\r
+ listItemChildren = child.children,\r
+ count = listItemChildren.length,\r
+ last = listItemChildren[ count - 1 ];\r
+\r
+ // Move out nested list.\r
+ if ( last.name in CKEDITOR.dtd.$list )\r
+ {\r
+ element.add( last, i + 1 );\r
+\r
+ // Remove the parent list item if it's just a holder.\r
+ if ( !--listItemChildren.length )\r
+ children.splice( i--, 1 );\r
+ }\r
+\r
+ child.name = 'cke:li';\r
+\r
+ // Inherit numbering from list root on the first list item.\r
+ attrs.start && !i && ( attributes.value = attrs.start );\r
+\r
+ plugin.filters.stylesFilter(\r
+ [\r
+ [ 'tab-stops', null, function( val )\r
+ {\r
+ var margin = val.split( ' ' )[ 1 ].match( cssLengthRelativeUnit );\r
+ margin && ( previousListItemMargin = CKEDITOR.tools.convertToPx( margin[ 0 ] ) );\r
+ } ],\r
+ ( level == 1 ? [ 'mso-list', null, function( val )\r
+ {\r
+ val = val.split( ' ' );\r
+ var listId = Number( val[ 0 ].match( /\d+/ ) );\r
+ listId !== previousListId && ( attributes[ 'cke:reset' ] = 1 );\r
+ previousListId = listId;\r
+ } ] : null )\r
+ ] )( attributes.style );\r
+\r
+ attributes[ 'cke:indent' ] = level;\r
+ attributes[ 'cke:listtype' ] = element.name;\r
+ attributes[ 'cke:list-style-type' ] = listStyleType;\r
+ }\r
+ // Flatten sub list.\r
+ else if ( child.name in CKEDITOR.dtd.$list )\r
+ {\r
+ // Absorb sub list children.\r
+ arguments.callee.apply( this, [ child, level + 1 ] );\r
+ children = children.slice( 0, i ).concat( child.children ).concat( children.slice( i + 1 ) );\r
+ element.children = [];\r
+ for ( var j = 0, num = children.length; j < num ; j++ )\r
+ element.add( children[ j ] );\r
+ }\r
+ }\r
+\r
+ delete element.name;\r
+\r
+ // We're loosing tag name here, signalize this element as a list.\r
+ attrs[ 'cke:list' ] = 1;\r
+ },\r
+\r
+ /**\r
+ * Try to collect all list items among the children and establish one\r
+ * or more HTML list structures for them.\r
+ * @param element\r
+ */\r
+ assembleList : function( element )\r
+ {\r
+ var children = element.children, child,\r
+ listItem, // The current processing cke:li element.\r
+ listItemAttrs,\r
+ listItemIndent, // Indent level of current list item.\r
+ lastIndent,\r
+ lastListItem, // The previous one just been added to the list.\r
+ list, // Current staging list and it's parent list if any.\r
+ openedLists = [],\r
+ previousListStyleType,\r
+ previousListType;\r
+\r
+ // Properties of the list item are to be resolved from the list bullet.\r
+ var bullet,\r
+ listType,\r
+ listStyleType,\r
+ itemNumeric;\r
+\r
+ for ( var i = 0; i < children.length; i++ )\r
+ {\r
+ child = children[ i ];\r
+\r
+ if ( 'cke:li' == child.name )\r
+ {\r
+ child.name = 'li';\r
+ listItem = child;\r
+ listItemAttrs = listItem.attributes;\r
+ bullet = listItemAttrs[ 'cke:listsymbol' ];\r
+ bullet = bullet && bullet.match( /^(?:[(]?)([^\s]+?)([.)]?)$/ );\r
+ listType = listStyleType = itemNumeric = null;\r
+\r
+ if ( listItemAttrs[ 'cke:ignored' ] )\r
+ {\r
+ children.splice( i--, 1 );\r
+ continue;\r
+ }\r
+\r
+\r
+ // This's from a new list root.\r
+ listItemAttrs[ 'cke:reset' ] && ( list = lastIndent = lastListItem = null );\r
+\r
+ // List item indent level might come from a real list indentation or\r
+ // been resolved from a pseudo list item's margin value, even get\r
+ // no indentation at all.\r
+ listItemIndent = Number( listItemAttrs[ 'cke:indent' ] );\r
+\r
+ // We're moving out of the current list, cleaning up.\r
+ if ( listItemIndent != lastIndent )\r
+ previousListType = previousListStyleType = null;\r
+\r
+ // List type and item style are already resolved.\r
+ if ( !bullet )\r
+ {\r
+ listType = listItemAttrs[ 'cke:listtype' ] || 'ol';\r
+ listStyleType = listItemAttrs[ 'cke:list-style-type' ];\r
+ }\r
+ else\r
+ {\r
+ // Probably share the same list style type with previous list item,\r
+ // give it priority to avoid ambiguous between C(Alpha) and C.(Roman).\r
+ if ( previousListType && listMarkerPatterns[ previousListType ] [ previousListStyleType ].test( bullet[ 1 ] ) )\r
+ {\r
+ listType = previousListType;\r
+ listStyleType = previousListStyleType;\r
+ }\r
+ else\r
+ {\r
+ for ( var type in listMarkerPatterns )\r
+ {\r
+ for ( var style in listMarkerPatterns[ type ] )\r
+ {\r
+ if ( listMarkerPatterns[ type ][ style ].test( bullet[ 1 ] ) )\r
+ {\r
+ // Small numbering has higher priority, when dealing with ambiguous\r
+ // between C(Alpha) and C.(Roman).\r
+ if ( type == 'ol' && ( /alpha|roman/ ).test( style ) )\r
+ {\r
+ var num = /roman/.test( style ) ? fromRoman( bullet[ 1 ] ) : fromAlphabet( bullet[ 1 ] );\r
+ if ( !itemNumeric || num < itemNumeric )\r
+ {\r
+ itemNumeric = num;\r
+ listType = type;\r
+ listStyleType = style;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ listType = type;\r
+ listStyleType = style;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ // Simply use decimal/disc for the rest forms of unrepresentable\r
+ // numerals, e.g. Chinese..., but as long as there a second part\r
+ // included, it has a bigger chance of being a order list ;)\r
+ !listType && ( listType = bullet[ 2 ] ? 'ol' : 'ul' );\r
+ }\r
+\r
+ previousListType = listType;\r
+ previousListStyleType = listStyleType || ( listType == 'ol' ? 'decimal' : 'disc' );\r
+ if ( listStyleType && listStyleType != ( listType == 'ol' ? 'decimal' : 'disc' ) )\r
+ listItem.addStyle( 'list-style-type', listStyleType );\r
+\r
+ // Figure out start numbering.\r
+ if ( listType == 'ol' && bullet )\r
+ {\r
+ switch ( listStyleType )\r
+ {\r
+ case 'decimal' :\r
+ itemNumeric = Number( bullet[ 1 ] );\r
+ break;\r
+ case 'lower-roman':\r
+ case 'upper-roman':\r
+ itemNumeric = fromRoman( bullet[ 1 ] );\r
+ break;\r
+ case 'lower-alpha':\r
+ case 'upper-alpha':\r
+ itemNumeric = fromAlphabet( bullet[ 1 ] );\r
+ break;\r
+ }\r
+\r
+ // Always create the numbering, swipe out unnecessary ones later.\r
+ listItem.attributes.value = itemNumeric;\r
+ }\r
+\r
+ // Start the list construction.\r
+ if ( !list )\r
+ {\r
+ openedLists.push( list = new CKEDITOR.htmlParser.element( listType ) );\r
+ list.add( listItem );\r
+ children[ i ] = list;\r
+ }\r
+ else\r
+ {\r
+ if ( listItemIndent > lastIndent )\r
+ {\r
+ openedLists.push( list = new CKEDITOR.htmlParser.element( listType ) );\r
+ list.add( listItem );\r
+ lastListItem.add( list );\r
+ }\r
+ else if ( listItemIndent < lastIndent )\r
+ {\r
+ // There might be a negative gap between two list levels. (#4944)\r
+ var diff = lastIndent - listItemIndent,\r
+ parent;\r
+ while ( diff-- && ( parent = list.parent ) )\r
+ list = parent.parent;\r
+\r
+ list.add( listItem );\r
+ }\r
+ else\r
+ list.add( listItem );\r
+\r
+ children.splice( i--, 1 );\r
+ }\r
+\r
+ lastListItem = listItem;\r
+ lastIndent = listItemIndent;\r
+ }\r
+ else if ( list )\r
+ list = lastIndent = lastListItem = null;\r
+ }\r
+\r
+ for ( i = 0; i < openedLists.length; i++ )\r
+ postProcessList( openedLists[ i ] );\r
+\r
+ list = lastIndent = lastListItem = previousListId = previousListItemMargin = listBaseIndent = null;\r
+ },\r
+\r
+ /**\r
+ * A simple filter which always rejecting.\r
+ */\r
+ falsyFilter : function( value )\r
+ {\r
+ return false;\r
+ },\r
+\r
+ /**\r
+ * A filter dedicated on the 'style' attribute filtering, e.g. dropping/replacing style properties.\r
+ * @param styles {Array} in form of [ styleNameRegexp, styleValueRegexp,\r
+ * newStyleValue/newStyleGenerator, newStyleName ] where only the first\r
+ * parameter is mandatory.\r
+ * @param whitelist {Boolean} Whether the {@param styles} will be considered as a white-list.\r
+ */\r
+ stylesFilter : function( styles, whitelist )\r
+ {\r
+ return function( styleText, element )\r
+ {\r
+ var rules = [];\r
+ // html-encoded quote might be introduced by 'font-family'\r
+ // from MS-Word which confused the following regexp. e.g.\r
+ //'font-family: "Lucida, Console"'\r
+ ( styleText || '' )\r
+ .replace( /"/g, '"' )\r
+ .replace( /\s*([^ :;]+)\s*:\s*([^;]+)\s*(?=;|$)/g,\r
+ function( match, name, value )\r
+ {\r
+ name = name.toLowerCase();\r
+ name == 'font-family' && ( value = value.replace( /["']/g, '' ) );\r
+\r
+ var namePattern,\r
+ valuePattern,\r
+ newValue,\r
+ newName;\r
+ for ( var i = 0 ; i < styles.length; i++ )\r
+ {\r
+ if ( styles[ i ] )\r
+ {\r
+ namePattern = styles[ i ][ 0 ];\r
+ valuePattern = styles[ i ][ 1 ];\r
+ newValue = styles[ i ][ 2 ];\r
+ newName = styles[ i ][ 3 ];\r
+\r
+ if ( name.match( namePattern )\r
+ && ( !valuePattern || value.match( valuePattern ) ) )\r
+ {\r
+ name = newName || name;\r
+ whitelist && ( newValue = newValue || value );\r
+\r
+ if ( typeof newValue == 'function' )\r
+ newValue = newValue( value, element, name );\r
+\r
+ // Return an couple indicate both name and value\r
+ // changed.\r
+ if ( newValue && newValue.push )\r
+ name = newValue[ 0 ], newValue = newValue[ 1 ];\r
+\r
+ if ( typeof newValue == 'string' )\r
+ rules.push( [ name, newValue ] );\r
+ return;\r
+ }\r
+ }\r
+ }\r
+\r
+ !whitelist && rules.push( [ name, value ] );\r
+\r
+ });\r
+\r
+ for ( var i = 0 ; i < rules.length ; i++ )\r
+ rules[ i ] = rules[ i ].join( ':' );\r
+ return rules.length ?\r
+ ( rules.join( ';' ) + ';' ) : false;\r
+ };\r
+ },\r
+\r
+ /**\r
+ * Migrate the element by decorate styles on it.\r
+ * @param styleDefiniton\r
+ * @param variables\r
+ */\r
+ elementMigrateFilter : function ( styleDefiniton, variables )\r
+ {\r
+ return function( element )\r
+ {\r
+ var styleDef =\r
+ variables ?\r
+ new CKEDITOR.style( styleDefiniton, variables )._.definition\r
+ : styleDefiniton;\r
+ element.name = styleDef.element;\r
+ CKEDITOR.tools.extend( element.attributes, CKEDITOR.tools.clone( styleDef.attributes ) );\r
+ element.addStyle( CKEDITOR.style.getStyleText( styleDef ) );\r
+ };\r
+ },\r
+\r
+ /**\r
+ * Migrate styles by creating a new nested stylish element.\r
+ * @param styleDefinition\r
+ */\r
+ styleMigrateFilter : function( styleDefinition, variableName )\r
+ {\r
+\r
+ var elementMigrateFilter = this.elementMigrateFilter;\r
+ return function( value, element )\r
+ {\r
+ // Build an stylish element first.\r
+ var styleElement = new CKEDITOR.htmlParser.element( null ),\r
+ variables = {};\r
+\r
+ variables[ variableName ] = value;\r
+ elementMigrateFilter( styleDefinition, variables )( styleElement );\r
+ // Place the new element inside the existing span.\r
+ styleElement.children = element.children;\r
+ element.children = [ styleElement ];\r
+ };\r
+ },\r
+\r
+ /**\r
+ * A filter which remove cke-namespaced-attribute on\r
+ * all none-cke-namespaced elements.\r
+ * @param value\r
+ * @param element\r
+ */\r
+ bogusAttrFilter : function( value, element )\r
+ {\r
+ if ( element.name.indexOf( 'cke:' ) == -1 )\r
+ return false;\r
+ },\r
+\r
+ /**\r
+ * A filter which will be used to apply inline css style according the stylesheet\r
+ * definition rules, is generated lazily when filtering.\r
+ */\r
+ applyStyleFilter : null\r
+\r
+ },\r
+\r
+ getRules : function( editor )\r
+ {\r
+ var dtd = CKEDITOR.dtd,\r
+ blockLike = CKEDITOR.tools.extend( {}, dtd.$block, dtd.$listItem, dtd.$tableContent ),\r
+ config = editor.config,\r
+ filters = this.filters,\r
+ falsyFilter = filters.falsyFilter,\r
+ stylesFilter = filters.stylesFilter,\r
+ elementMigrateFilter = filters.elementMigrateFilter,\r
+ styleMigrateFilter = CKEDITOR.tools.bind( this.filters.styleMigrateFilter, this.filters ),\r
+ createListBulletMarker = this.utils.createListBulletMarker,\r
+ flattenList = filters.flattenList,\r
+ assembleList = filters.assembleList,\r
+ isListBulletIndicator = this.utils.isListBulletIndicator,\r
+ containsNothingButSpaces = this.utils.isContainingOnlySpaces,\r
+ resolveListItem = this.utils.resolveList,\r
+ convertToPx = function( value )\r
+ {\r
+ value = CKEDITOR.tools.convertToPx( value );\r
+ return isNaN( value ) ? value : value + 'px';\r
+ },\r
+ getStyleComponents = this.utils.getStyleComponents,\r
+ listDtdParents = this.utils.listDtdParents,\r
+ removeFontStyles = config.pasteFromWordRemoveFontStyles !== false,\r
+ removeStyles = config.pasteFromWordRemoveStyles !== false;\r
+\r
+ return {\r
+\r
+ elementNames :\r
+ [\r
+ // Remove script, meta and link elements.\r
+ [ ( /meta|link|script/ ), '' ]\r
+ ],\r
+\r
+ root : function( element )\r
+ {\r
+ element.filterChildren();\r
+ assembleList( element );\r
+ },\r
+\r
+ elements :\r
+ {\r
+ '^' : function( element )\r
+ {\r
+ // Transform CSS style declaration to inline style.\r
+ var applyStyleFilter;\r
+ if ( CKEDITOR.env.gecko && ( applyStyleFilter = filters.applyStyleFilter ) )\r
+ applyStyleFilter( element );\r
+ },\r
+\r
+ $ : function( element )\r
+ {\r
+ var tagName = element.name || '',\r
+ attrs = element.attributes;\r
+\r
+ // Convert length unit of width/height on blocks to\r
+ // a more editor-friendly way (px).\r
+ if ( tagName in blockLike\r
+ && attrs.style )\r
+ {\r
+ attrs.style = stylesFilter(\r
+ [ [ ( /^(:?width|height)$/ ), null, convertToPx ] ] )( attrs.style ) || '';\r
+ }\r
+\r
+ // Processing headings.\r
+ if ( tagName.match( /h\d/ ) )\r
+ {\r
+ element.filterChildren();\r
+ // Is the heading actually a list item?\r
+ if ( resolveListItem( element ) )\r
+ return;\r
+\r
+ // Adapt heading styles to editor's convention.\r
+ elementMigrateFilter( config[ 'format_' + tagName ] )( element );\r
+ }\r
+ // Remove inline elements which contain only empty spaces.\r
+ else if ( tagName in dtd.$inline )\r
+ {\r
+ element.filterChildren();\r
+ if ( containsNothingButSpaces( element ) )\r
+ delete element.name;\r
+ }\r
+ // Remove element with ms-office namespace,\r
+ // with it's content preserved, e.g. 'o:p'.\r
+ else if ( tagName.indexOf( ':' ) != -1\r
+ && tagName.indexOf( 'cke' ) == -1 )\r
+ {\r
+ element.filterChildren();\r
+\r
+ // Restore image real link from vml.\r
+ if ( tagName == 'v:imagedata' )\r
+ {\r
+ var href = element.attributes[ 'o:href' ];\r
+ if ( href )\r
+ element.attributes.src = href;\r
+ element.name = 'img';\r
+ return;\r
+ }\r
+ delete element.name;\r
+ }\r
+\r
+ // Assembling list items into a whole list.\r
+ if ( tagName in listDtdParents )\r
+ {\r
+ element.filterChildren();\r
+ assembleList( element );\r
+ }\r
+ },\r
+\r
+ // We'll drop any style sheet, but Firefox conclude\r
+ // certain styles in a single style element, which are\r
+ // required to be changed into inline ones.\r
+ 'style' : function( element )\r
+ {\r
+ if ( CKEDITOR.env.gecko )\r
+ {\r
+ // Grab only the style definition section.\r
+ var styleDefSection = element.onlyChild().value.match( /\/\* Style Definitions \*\/([\s\S]*?)\/\*/ ),\r
+ styleDefText = styleDefSection && styleDefSection[ 1 ],\r
+ rules = {}; // Storing the parsed result.\r
+\r
+ if ( styleDefText )\r
+ {\r
+ styleDefText\r
+ // Remove line-breaks.\r
+ .replace(/[\n\r]/g,'')\r
+ // Extract selectors and style properties.\r
+ .replace( /(.+?)\{(.+?)\}/g,\r
+ function( rule, selectors, styleBlock )\r
+ {\r
+ selectors = selectors.split( ',' );\r
+ var length = selectors.length, selector;\r
+ for ( var i = 0; i < length; i++ )\r
+ {\r
+ // Assume MS-Word mostly generate only simple\r
+ // selector( [Type selector][Class selector]).\r
+ CKEDITOR.tools.trim( selectors[ i ] )\r
+ .replace( /^(\w+)(\.[\w-]+)?$/g,\r
+ function( match, tagName, className )\r
+ {\r
+ tagName = tagName || '*';\r
+ className = className.substring( 1, className.length );\r
+\r
+ // Reject MS-Word Normal styles.\r
+ if ( className.match( /MsoNormal/ ) )\r
+ return;\r
+\r
+ if ( !rules[ tagName ] )\r
+ rules[ tagName ] = {};\r
+ if ( className )\r
+ rules[ tagName ][ className ] = styleBlock;\r
+ else\r
+ rules[ tagName ] = styleBlock;\r
+ } );\r
+ }\r
+ });\r
+\r
+ filters.applyStyleFilter = function( element )\r
+ {\r
+ var name = rules[ '*' ] ? '*' : element.name,\r
+ className = element.attributes && element.attributes[ 'class' ],\r
+ style;\r
+ if ( name in rules )\r
+ {\r
+ style = rules[ name ];\r
+ if ( typeof style == 'object' )\r
+ style = style[ className ];\r
+ // Maintain style rules priorities.\r
+ style && element.addStyle( style, true );\r
+ }\r
+ };\r
+ }\r
+ }\r
+ return false;\r
+ },\r
+\r
+ 'p' : function( element )\r
+ {\r
+ // This's a fall-back approach to recognize list item in FF3.6,\r
+ // as it's not perfect as not all list style (e.g. "heading list") is shipped\r
+ // with this pattern. (#6662)\r
+ if ( /MsoListParagraph/.exec( element.attributes[ 'class' ] ) )\r
+ {\r
+ var bulletText = element.firstChild( function( node )\r
+ {\r
+ return node.type == CKEDITOR.NODE_TEXT && !containsNothingButSpaces( node.parent );\r
+ });\r
+ var bullet = bulletText && bulletText.parent,\r
+ bulletAttrs = bullet && bullet.attributes;\r
+ bulletAttrs && !bulletAttrs.style && ( bulletAttrs.style = 'mso-list: Ignore;' );\r
+ }\r
+\r
+ element.filterChildren();\r
+\r
+ // Is the paragraph actually a list item?\r
+ if ( resolveListItem( element ) )\r
+ return;\r
+\r
+ // Adapt paragraph formatting to editor's convention\r
+ // according to enter-mode.\r
+ if ( config.enterMode == CKEDITOR.ENTER_BR )\r
+ {\r
+ // We suffer from attribute/style lost in this situation.\r
+ delete element.name;\r
+ element.add( new CKEDITOR.htmlParser.element( 'br' ) );\r
+ }\r
+ else\r
+ elementMigrateFilter( config[ 'format_' + ( config.enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) ] )( element );\r
+ },\r
+\r
+ 'div' : function( element )\r
+ {\r
+ // Aligned table with no text surrounded is represented by a wrapper div, from which\r
+ // table cells inherit as text-align styles, which is wrong.\r
+ // Instead we use a clear-float div after the table to properly achieve the same layout.\r
+ var singleChild = element.onlyChild();\r
+ if ( singleChild && singleChild.name == 'table' )\r
+ {\r
+ var attrs = element.attributes;\r
+ singleChild.attributes = CKEDITOR.tools.extend( singleChild.attributes, attrs );\r
+ attrs.style && singleChild.addStyle( attrs.style );\r
+\r
+ var clearFloatDiv = new CKEDITOR.htmlParser.element( 'div' );\r
+ clearFloatDiv.addStyle( 'clear' ,'both' );\r
+ element.add( clearFloatDiv );\r
+ delete element.name;\r
+ }\r
+ },\r
+\r
+ 'td' : function ( element )\r
+ {\r
+ // 'td' in 'thead' is actually <th>.\r
+ if ( element.getAncestor( 'thead') )\r
+ element.name = 'th';\r
+ },\r
+\r
+ // MS-Word sometimes present list as a mixing of normal list\r
+ // and pseudo-list, normalize the previous ones into pseudo form.\r
+ 'ol' : flattenList,\r
+ 'ul' : flattenList,\r
+ 'dl' : flattenList,\r
+\r
+ 'font' : function( element )\r
+ {\r
+ // Drop the font tag if it comes from list bullet text.\r
+ if ( isListBulletIndicator( element.parent ) )\r
+ {\r
+ delete element.name;\r
+ return;\r
+ }\r
+\r
+ element.filterChildren();\r
+\r
+ var attrs = element.attributes,\r
+ styleText = attrs.style,\r
+ parent = element.parent;\r
+\r
+ if ( 'font' == parent.name ) // Merge nested <font> tags.\r
+ {\r
+ CKEDITOR.tools.extend( parent.attributes,\r
+ element.attributes );\r
+ styleText && parent.addStyle( styleText );\r
+ delete element.name;\r
+ }\r
+ // Convert the merged into a span with all attributes preserved.\r
+ else\r
+ {\r
+ styleText = styleText || '';\r
+ // IE's having those deprecated attributes, normalize them.\r
+ if ( attrs.color )\r
+ {\r
+ attrs.color != '#000000' && ( styleText += 'color:' + attrs.color + ';' );\r
+ delete attrs.color;\r
+ }\r
+ if ( attrs.face )\r
+ {\r
+ styleText += 'font-family:' + attrs.face + ';';\r
+ delete attrs.face;\r
+ }\r
+ // TODO: Mapping size in ranges of xx-small,\r
+ // x-small, small, medium, large, x-large, xx-large.\r
+ if ( attrs.size )\r
+ {\r
+ styleText += 'font-size:' +\r
+ ( attrs.size > 3 ? 'large'\r
+ : ( attrs.size < 3 ? 'small' : 'medium' ) ) + ';';\r
+ delete attrs.size;\r
+ }\r
+\r
+ element.name = 'span';\r
+ element.addStyle( styleText );\r
+ }\r
+ },\r
+\r
+ 'span' : function( element )\r
+ {\r
+ // Remove the span if it comes from list bullet text.\r
+ if ( isListBulletIndicator( element.parent ) )\r
+ return false;\r
+\r
+ element.filterChildren();\r
+ if ( containsNothingButSpaces( element ) )\r
+ {\r
+ delete element.name;\r
+ return null;\r
+ }\r
+\r
+ // List item bullet type is supposed to be indicated by\r
+ // the text of a span with style 'mso-list : Ignore' or an image.\r
+ if ( isListBulletIndicator( element ) )\r
+ {\r
+ var listSymbolNode = element.firstChild( function( node )\r
+ {\r
+ return node.value || node.name == 'img';\r
+ });\r
+\r
+ var listSymbol = listSymbolNode && ( listSymbolNode.value || 'l.' ),\r
+ listType = listSymbol && listSymbol.match( /^(?:[(]?)([^\s]+?)([.)]?)$/ );\r
+\r
+ if ( listType )\r
+ {\r
+ var marker = createListBulletMarker( listType, listSymbol );\r
+ // Some non-existed list items might be carried by an inconsequential list, indicate by "mso-hide:all/display:none",\r
+ // those are to be removed later, now mark it with "cke:ignored".\r
+ var ancestor = element.getAncestor( 'span' );\r
+ if ( ancestor && (/ mso-hide:\s*all|display:\s*none /).test( ancestor.attributes.style ) )\r
+ marker.attributes[ 'cke:ignored' ] = 1;\r
+ return marker;\r
+ }\r
+ }\r
+\r
+ // Update the src attribute of image element with href.\r
+ var children = element.children,\r
+ attrs = element.attributes,\r
+ styleText = attrs && attrs.style,\r
+ firstChild = children && children[ 0 ];\r
+\r
+ // Assume MS-Word mostly carry font related styles on <span>,\r
+ // adapting them to editor's convention.\r
+ if ( styleText )\r
+ {\r
+ attrs.style = stylesFilter(\r
+ [\r
+ // Drop 'inline-height' style which make lines overlapping.\r
+ [ 'line-height' ],\r
+ [ ( /^font-family$/ ), null, !removeFontStyles ? styleMigrateFilter( config[ 'font_style' ], 'family' ) : null ] ,\r
+ [ ( /^font-size$/ ), null, !removeFontStyles ? styleMigrateFilter( config[ 'fontSize_style' ], 'size' ) : null ] ,\r
+ [ ( /^color$/ ), null, !removeFontStyles ? styleMigrateFilter( config[ 'colorButton_foreStyle' ], 'color' ) : null ] ,\r
+ [ ( /^background-color$/ ), null, !removeFontStyles ? styleMigrateFilter( config[ 'colorButton_backStyle' ], 'color' ) : null ]\r
+ ] )( styleText, element ) || '';\r
+ }\r
+\r
+ return null;\r
+ },\r
+\r
+ // Migrate basic style formats to editor configured ones.\r
+ 'b' : elementMigrateFilter( config[ 'coreStyles_bold' ] ),\r
+ 'i' : elementMigrateFilter( config[ 'coreStyles_italic' ] ),\r
+ 'u' : elementMigrateFilter( config[ 'coreStyles_underline' ] ),\r
+ 's' : elementMigrateFilter( config[ 'coreStyles_strike' ] ),\r
+ 'sup' : elementMigrateFilter( config[ 'coreStyles_superscript' ] ),\r
+ 'sub' : elementMigrateFilter( config[ 'coreStyles_subscript' ] ),\r
+ // Editor doesn't support anchor with content currently (#3582),\r
+ // drop such anchors with content preserved.\r
+ 'a' : function( element )\r
+ {\r
+ var attrs = element.attributes;\r
+ if ( attrs && !attrs.href && attrs.name )\r
+ delete element.name;\r
+ else if ( CKEDITOR.env.webkit && attrs.href && attrs.href.match( /file:\/\/\/[\S]+#/i ) )\r
+ attrs.href = attrs.href.replace( /file:\/\/\/[^#]+/i,'' );\r
+ },\r
+ 'cke:listbullet' : function( element )\r
+ {\r
+ if ( element.getAncestor( /h\d/ ) && !config.pasteFromWordNumberedHeadingToList )\r
+ delete element.name;\r
+ }\r
+ },\r
+\r
+ attributeNames :\r
+ [\r
+ // Remove onmouseover and onmouseout events (from MS Word comments effect)\r
+ [ ( /^onmouse(:?out|over)/ ), '' ],\r
+ // Onload on image element.\r
+ [ ( /^onload$/ ), '' ],\r
+ // Remove office and vml attribute from elements.\r
+ [ ( /(?:v|o):\w+/ ), '' ],\r
+ // Remove lang/language attributes.\r
+ [ ( /^lang/ ), '' ]\r
+ ],\r
+\r
+ attributes :\r
+ {\r
+ 'style' : stylesFilter(\r
+ removeStyles ?\r
+ // Provide a white-list of styles that we preserve, those should\r
+ // be the ones that could later be altered with editor tools.\r
+ [\r
+ // Leave list-style-type\r
+ [ ( /^list-style-type$/ ), null ],\r
+\r
+ // Preserve margin-left/right which used as default indent style in the editor.\r
+ [ ( /^margin$|^margin-(?!bottom|top)/ ), null, function( value, element, name )\r
+ {\r
+ if ( element.name in { p : 1, div : 1 } )\r
+ {\r
+ var indentStyleName = config.contentsLangDirection == 'ltr' ?\r
+ 'margin-left' : 'margin-right';\r
+\r
+ // Extract component value from 'margin' shorthand.\r
+ if ( name == 'margin' )\r
+ {\r
+ value = getStyleComponents( name, value,\r
+ [ indentStyleName ] )[ indentStyleName ];\r
+ }\r
+ else if ( name != indentStyleName )\r
+ return null;\r
+\r
+ if ( value && !emptyMarginRegex.test( value ) )\r
+ return [ indentStyleName, value ];\r
+ }\r
+\r
+ return null;\r
+ } ],\r
+\r
+ // Preserve clear float style.\r
+ [ ( /^clear$/ ) ],\r
+\r
+ [ ( /^border.*|margin.*|vertical-align|float$/ ), null,\r
+ function( value, element )\r
+ {\r
+ if ( element.name == 'img' )\r
+ return value;\r
+ } ],\r
+\r
+ [ (/^width|height$/ ), null,\r
+ function( value, element )\r
+ {\r
+ if ( element.name in { table : 1, td : 1, th : 1, img : 1 } )\r
+ return value;\r
+ } ]\r
+ ] :\r
+ // Otherwise provide a black-list of styles that we remove.\r
+ [\r
+ [ ( /^mso-/ ) ],\r
+ // Fixing color values.\r
+ [ ( /-color$/ ), null, function( value )\r
+ {\r
+ if ( value == 'transparent' )\r
+ return false;\r
+ if ( CKEDITOR.env.gecko )\r
+ return value.replace( /-moz-use-text-color/g, 'transparent' );\r
+ } ],\r
+ // Remove empty margin values, e.g. 0.00001pt 0em 0pt\r
+ [ ( /^margin$/ ), emptyMarginRegex ],\r
+ [ 'text-indent', '0cm' ],\r
+ [ 'page-break-before' ],\r
+ [ 'tab-stops' ],\r
+ [ 'display', 'none' ],\r
+ removeFontStyles ? [ ( /font-?/ ) ] : null\r
+ ], removeStyles ),\r
+\r
+ // Prefer width styles over 'width' attributes.\r
+ 'width' : function( value, element )\r
+ {\r
+ if ( element.name in dtd.$tableContent )\r
+ return false;\r
+ },\r
+ // Prefer border styles over table 'border' attributes.\r
+ 'border' : function( value, element )\r
+ {\r
+ if ( element.name in dtd.$tableContent )\r
+ return false;\r
+ },\r
+\r
+ // Only Firefox carry style sheet from MS-Word, which\r
+ // will be applied by us manually. For other browsers\r
+ // the css className is useless.\r
+ 'class' : falsyFilter,\r
+\r
+ // MS-Word always generate 'background-color' along with 'bgcolor',\r
+ // simply drop the deprecated attributes.\r
+ 'bgcolor' : falsyFilter,\r
+\r
+ // Deprecate 'valign' attribute in favor of 'vertical-align'.\r
+ 'valign' : removeStyles ? falsyFilter : function( value, element )\r
+ {\r
+ element.addStyle( 'vertical-align', value );\r
+ return false;\r
+ }\r
+ },\r
+\r
+ // Fore none-IE, some useful data might be buried under these IE-conditional\r
+ // comments where RegExp were the right approach to dig them out where usual approach\r
+ // is transform it into a fake element node which hold the desired data.\r
+ comment :\r
+ !CKEDITOR.env.ie ?\r
+ function( value, node )\r
+ {\r
+ var imageInfo = value.match( /<img.*?>/ ),\r
+ listInfo = value.match( /^\[if !supportLists\]([\s\S]*?)\[endif\]$/ );\r
+\r
+ // Seek for list bullet indicator.\r
+ if ( listInfo )\r
+ {\r
+ // Bullet symbol could be either text or an image.\r
+ var listSymbol = listInfo[ 1 ] || ( imageInfo && 'l.' ),\r
+ listType = listSymbol && listSymbol.match( />(?:[(]?)([^\s]+?)([.)]?)</ );\r
+ return createListBulletMarker( listType, listSymbol );\r
+ }\r
+\r
+ // Reveal the <img> element in conditional comments for Firefox.\r
+ if ( CKEDITOR.env.gecko && imageInfo )\r
+ {\r
+ var img = CKEDITOR.htmlParser.fragment.fromHtml( imageInfo[ 0 ] ).children[ 0 ],\r
+ previousComment = node.previous,\r
+ // Try to dig the real image link from vml markup from previous comment text.\r
+ imgSrcInfo = previousComment && previousComment.value.match( /<v:imagedata[^>]*o:href=['"](.*?)['"]/ ),\r
+ imgSrc = imgSrcInfo && imgSrcInfo[ 1 ];\r
+\r
+ // Is there a real 'src' url to be used?\r
+ imgSrc && ( img.attributes.src = imgSrc );\r
+ return img;\r
+ }\r
+\r
+ return false;\r
+ }\r
+ : falsyFilter\r
+ };\r
+ }\r
+ });\r
+\r
+ // The paste processor here is just a reduced copy of html data processor.\r
+ var pasteProcessor = function()\r
+ {\r
+ this.dataFilter = new CKEDITOR.htmlParser.filter();\r
+ };\r
+\r
+ pasteProcessor.prototype =\r
+ {\r
+ toHtml : function( data )\r
+ {\r
+ var fragment = CKEDITOR.htmlParser.fragment.fromHtml( data, false ),\r
+ writer = new CKEDITOR.htmlParser.basicWriter();\r
+\r
+ fragment.writeHtml( writer, this.dataFilter );\r
+ return writer.getHtml( true );\r
+ }\r
+ };\r
+\r
+ CKEDITOR.cleanWord = function( data, editor )\r
+ {\r
+ // Firefox will be confused by those downlevel-revealed IE conditional\r
+ // comments, fixing them first( convert it to upperlevel-revealed one ).\r
+ // e.g. <![if !vml]>...<![endif]>\r
+ if ( CKEDITOR.env.gecko )\r
+ data = data.replace( /(<!--\[if[^<]*?\])-->([\S\s]*?)<!--(\[endif\]-->)/gi, '$1$2$3' );\r
+\r
+ var dataProcessor = new pasteProcessor(),\r
+ dataFilter = dataProcessor.dataFilter;\r
+\r
+ // These rules will have higher priorities than default ones.\r
+ dataFilter.addRules( CKEDITOR.plugins.pastefromword.getRules( editor ) );\r
+\r
+ // Allow extending data filter rules.\r
+ editor.fire( 'beforeCleanWord', { filter : dataFilter } );\r
+\r
+ try\r
+ {\r
+ data = dataProcessor.toHtml( data, false );\r
+ }\r
+ catch ( e )\r
+ {\r
+ alert( editor.lang.pastefromword.error );\r
+ }\r
+\r
+ /* Below post processing those things that are unable to delivered by filter rules. */\r
+\r
+ // Remove 'cke' namespaced attribute used in filter rules as marker.\r
+ data = data.replace( /cke:.*?".*?"/g, '' );\r
+\r
+ // Remove empty style attribute.\r
+ data = data.replace( /style=""/g, '' );\r
+\r
+ // Remove the dummy spans ( having no inline style ).\r
+ data = data.replace( /<span>/g, '' );\r
+\r
+ return data;\r
+ };\r
+})();\r
+\r
+/**\r
+ * Whether to ignore all font related formatting styles, including:\r
+ * <ul> <li>font size;</li>\r
+ * <li>font family;</li>\r
+ * <li>font foreground/background color.</li></ul>\r
+ * @name CKEDITOR.config.pasteFromWordRemoveFontStyles\r
+ * @since 3.1\r
+ * @type Boolean\r
+ * @default true\r
+ * @example\r
+ * config.pasteFromWordRemoveFontStyles = false;\r
+ */\r
+\r
+/**\r
+ * Whether to transform MS Word outline numbered headings into lists.\r
+ * @name CKEDITOR.config.pasteFromWordNumberedHeadingToList\r
+ * @since 3.1\r
+ * @type Boolean\r
+ * @default false\r
+ * @example\r
+ * config.pasteFromWordNumberedHeadingToList = true;\r
+ */\r
+\r
+/**\r
+ * Whether to remove element styles that can't be managed with the editor. Note\r
+ * that this doesn't handle the font specific styles, which depends on the\r
+ * {@link CKEDITOR.config.pasteFromWordRemoveFontStyles} setting instead.\r
+ * @name CKEDITOR.config.pasteFromWordRemoveStyles\r
+ * @since 3.1\r
+ * @type Boolean\r
+ * @default true\r
+ * @example\r
+ * config.pasteFromWordRemoveStyles = false;\r
+ */\r