diff --git a/CHANGES.md b/CHANGES.md index 0acf7cd6302..52dba53d7bf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,11 +10,12 @@ Fixed Issues: * [#12885](http://dev.ckeditor.com/ticket/12885): Added missing getData parameter documentation. * [#11982](http://dev.ckeditor.com/ticket/11982): Bullet added in wrong position after *enter* key pressed in nested list. * [#13027](http://dev.ckeditor.com/ticket/13027): Fixed: Keyboard Navigation in dialogs with multiple tabs not following CI 162 instructions or [ARIA Authoring practices](http://www.w3.org/TR/2013/WD-wai-aria-practices-20130307/#tabpanel). +* [#12256](http://dev.ckeditor.com/ticket/12256): Fixed: Basic styles' classes are lost when pasting from MS Word if [basics styles](http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-coreStyles_bold) were configured to use classes. Other Changes: * [#12844](http://dev.ckeditor.com/ticket/12844): Upgraded the [testing environment](http://docs.ckeditor.com/#!/guide/dev_tests) to [Bender.js](https://github.com/benderjs/benderjs) `0.2.*`. -* [#12930](http://dev.ckeditor.com/ticket/12930): Because of licenses, removed truncated-mathjax from the test directory, now `bender.config.mathJaxLibPath` need to be configured manually. +* [#12930](http://dev.ckeditor.com/ticket/12930): Because of licenses, removed `truncated-mathjax/` from the `tests/` directory. Now `bender.config.mathJaxLibPath` must be configured manually in order to run MathJax plugin's tests. ## CKEditor 4.4.7 diff --git a/plugins/pastefromword/filter/default.js b/plugins/pastefromword/filter/default.js index 0b84da34e3f..5d2037c1a02 100644 --- a/plugins/pastefromword/filter/default.js +++ b/plugins/pastefromword/filter/default.js @@ -596,6 +596,10 @@ element.name = styleDef.element; CKEDITOR.tools.extend( element.attributes, CKEDITOR.tools.clone( styleDef.attributes ) ); element.addStyle( CKEDITOR.style.getStyleText( styleDef ) ); + // Mark style classes as allowed so they will not be filtered out (#12256). + if ( styleDef.attributes && styleDef.attributes[ 'class' ] ) { + element.classWhiteList = ' ' + styleDef.attributes[ 'class' ] + ' '; + } } : function() {}; }, @@ -1058,7 +1062,13 @@ // Only Firefox carry style sheet from MS-Word, which // will be applied by us manually. For other browsers // the css className is useless. - 'class': falsyFilter, + // We need to keep classes added as a style (#12256). + 'class': function( value, element ) { + if ( element.classWhiteList && element.classWhiteList.indexOf( ' ' + value + ' ' ) != -1 ) { + return value; + } + return false; + }, // MS-Word always generate 'background-color' along with 'bgcolor', // simply drop the deprecated attributes. diff --git a/tests/plugins/pastefromword/manual/_assets/removedclasses.css b/tests/plugins/pastefromword/manual/_assets/removedclasses.css new file mode 100644 index 00000000000..2c8d18fdbab --- /dev/null +++ b/tests/plugins/pastefromword/manual/_assets/removedclasses.css @@ -0,0 +1,4 @@ +.myboldclass { + font-weight: bold; + color: red; +} \ No newline at end of file diff --git a/tests/plugins/pastefromword/manual/removedclasses.html b/tests/plugins/pastefromword/manual/removedclasses.html new file mode 100644 index 00000000000..90acf74e06e --- /dev/null +++ b/tests/plugins/pastefromword/manual/removedclasses.html @@ -0,0 +1,18 @@ + + \ No newline at end of file diff --git a/tests/plugins/pastefromword/manual/removedclasses.md b/tests/plugins/pastefromword/manual/removedclasses.md new file mode 100644 index 00000000000..d433691071b --- /dev/null +++ b/tests/plugins/pastefromword/manual/removedclasses.md @@ -0,0 +1,6 @@ +@bender-ui: collapsed +@bender-ckeditor-plugins: wysiwygarea, toolbar, undo, basicstyles, pastefromword, sourcearea, elementspath + +1. Paste bold text from word. + +Expected result: bold text should be bold and red. \ No newline at end of file diff --git a/tests/plugins/pastefromword/pastefromword.js b/tests/plugins/pastefromword/pastefromword.js index f07e157e552..b94f946718b 100644 --- a/tests/plugins/pastefromword/pastefromword.js +++ b/tests/plugins/pastefromword/pastefromword.js @@ -23,6 +23,36 @@ } ); wait(); + }, + + 'test keep custom class': function() { + bender.editorBot.create( { + name: 'keep_custom_class', + config: { + coreStyles_bold: { + element: 'span', + attributes: { 'class': 'customboldclass' }, + overrides: [ 'strong', 'b' ] + }, + allowedContent: true + } + }, function( bot ) { + var editor = bot.editor; + + editor.once( 'paste', function( evt ) { + var dataValue = evt.data.dataValue; + resume( function() { + assert.areSame( '

Foo bar bom

', dataValue ); + } ); + }, null, null, 5 ); // Test PFW only. + + editor.fire( 'paste', { + type: 'auto', + dataValue: '

Foo bar bom

' + } ); + + wait(); + } ); } } );