From 48220d0063664a8dd72f3b67e586cfda47e5adf0 Mon Sep 17 00:00:00 2001 From: Piotr Jasiun Date: Fri, 20 Mar 2015 17:12:02 +0100 Subject: [PATCH 1/4] Tests: both automated and manual. --- .../manual/_assets/removedclasses.css | 4 +++ .../pastefromword/manual/removedclasses.html | 18 ++++++++++++ .../pastefromword/manual/removedclasses.md | 6 ++++ tests/plugins/pastefromword/pastefromword.js | 29 +++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 tests/plugins/pastefromword/manual/_assets/removedclasses.css create mode 100644 tests/plugins/pastefromword/manual/removedclasses.html create mode 100644 tests/plugins/pastefromword/manual/removedclasses.md 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..12b9fdf6af0 100644 --- a/tests/plugins/pastefromword/pastefromword.js +++ b/tests/plugins/pastefromword/pastefromword.js @@ -23,6 +23,35 @@ } ); 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 ) { + resume( function() { + assert.areSame( '

Foo bar bom

', evt.data.dataValue ); + } ); + }, null, null, 999 ); + + editor.fire( 'paste', { + type: 'auto', + dataValue: '

Foo bar bom

' + } ); + + wait(); + } ); } } ); From fc1a9031f25198e273006b72b8ee101ef8392931 Mon Sep 17 00:00:00 2001 From: Piotr Jasiun Date: Fri, 20 Mar 2015 17:15:41 +0100 Subject: [PATCH 2/4] Fixed removing classes in paste from word filter. --- plugins/pastefromword/filter/default.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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. From d155a3271be9d981da3bdd9f1d0bf1a212ab228e Mon Sep 17 00:00:00 2001 From: Piotr Jasiun Date: Fri, 20 Mar 2015 17:43:47 +0100 Subject: [PATCH 3/4] Tests: Focus on testing only paste for word plugin. --- tests/plugins/pastefromword/pastefromword.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/plugins/pastefromword/pastefromword.js b/tests/plugins/pastefromword/pastefromword.js index 12b9fdf6af0..b94f946718b 100644 --- a/tests/plugins/pastefromword/pastefromword.js +++ b/tests/plugins/pastefromword/pastefromword.js @@ -40,10 +40,11 @@ var editor = bot.editor; editor.once( 'paste', function( evt ) { + var dataValue = evt.data.dataValue; resume( function() { - assert.areSame( '

Foo bar bom

', evt.data.dataValue ); + assert.areSame( '

Foo bar bom

', dataValue ); } ); - }, null, null, 999 ); + }, null, null, 5 ); // Test PFW only. editor.fire( 'paste', { type: 'auto', From 29ec90d51c838918edf2e7a21de369189a94c48d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Koszuli=C5=84ski?= Date: Wed, 25 Mar 2015 11:14:24 +0100 Subject: [PATCH 4/4] Changelog entry. --- CHANGES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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