Skip to content

Commit

Permalink
Merge branch 't/12750b'
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Dec 16, 2014
2 parents 3f0ab19 + 55ac525 commit a5f8c73
Show file tree
Hide file tree
Showing 3 changed files with 232 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Fixed Issues:

* [#12747](http://dev.ckeditor.com/ticket/12747): [IE8-10] Fixed: Opening a drop-down for a specific selection when editor is maximized results in incorrect drop-down panel position.
* [#12735](http://dev.ckeditor.com/ticket/12735): Fixed: [`Config.fillEmptyBlocks`](http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-fillEmptyBlocks) should only apply when outputting data.
* [#12750](http://dev.ckeditor.com/ticket/12750): Fixed: [Paste from Word](http://ckeditor.com/addon/pastefromword): strikethrough and underscore should have the same color as font.

## CKEditor 4.4.6

Expand Down Expand Up @@ -75,7 +76,7 @@ Fixed Issues:
Fixed Issues:

* [#12268](http://dev.ckeditor.com/ticket/12268): Cleanup of [UI Color](http://ckeditor.com/addon/uicolor) YUI styles. Thanks to [CasherWest](https://github.com/CasherWest)!
* [#12263](http://dev.ckeditor.com/ticket/12263): Fixed: [Paste from Word]((http://ckeditor.com/addon/pastefromword)) filter does not properly normalize semicolons style text. Thanks to [Alin Purcaru](https://github.com/mesmerizero)!
* [#12263](http://dev.ckeditor.com/ticket/12263): Fixed: [Paste from Word](http://ckeditor.com/addon/pastefromword) filter does not properly normalize semicolons style text. Thanks to [Alin Purcaru](https://github.com/mesmerizero)!
* [#12243](http://dev.ckeditor.com/ticket/12243): Fixed: Text formatting lost when pasting from Word. Thanks to [Alin Purcaru](https://github.com/mesmerizero)!
* [#111739](http://dev.ckeditor.com/ticket/11739): Fixed: `keypress` listeners should not be used in the undo manager. A complete rewrite of keyboard handling in the undo manager was made. Numerous smaller issues were fixed, among others:
* [#10926](http://dev.ckeditor.com/ticket/10926): [Chrome@Android] Fixed: Typing does not record snapshots and does not fire the [`editor.change`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-change) event.
Expand Down
49 changes: 45 additions & 4 deletions plugins/pastefromword/filter/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,37 @@

// A filter which will be used to apply inline css style according the stylesheet
// definition rules, is generated lazily when filtering.
applyStyleFilter: null
applyStyleFilter: null,

// Move element close to the child text elements.
// Return `1` is element was moved, `0` otherwise.
moveToText: function( element ) {
var children = element.children,
isEmpty = !children.length,
hasTextOnly = ( children.length == 1 && children[ 0 ].type == CKEDITOR.NODE_TEXT );

// Do not move elements marked as moved. Otherwise we will have infinite loop if two elements
// (<s> and <u>) would try to move.
if ( element._.moved || isEmpty || hasTextOnly ) {
return 0;
}

// Wrap every child text node.
element.forEach( function( node ) {
if ( node.type == CKEDITOR.NODE_TEXT ) {

var wrapper = new CKEDITOR.htmlParser.element( element.name, element.attributes );
wrapper._.moved = 1;

node.wrapWith( wrapper );
}
} );

// Replace element with children.
element.name = null;

return 1;
}
},

getRules: function( editor, filter ) {
Expand All @@ -652,6 +681,7 @@
createListBulletMarker = this.utils.createListBulletMarker,
flattenList = filters.flattenList,
assembleList = filters.assembleList,
moveToText = filters.moveToText,
isListBulletIndicator = this.utils.isListBulletIndicator,
containsNothingButSpaces = this.utils.isContainingOnlySpaces,
resolveListItem = this.utils.resolveList,
Expand Down Expand Up @@ -817,7 +847,7 @@
delete element.name;
element.add( new CKEDITOR.htmlParser.element( 'br' ) );
} else {
elementMigrateFilter( config['format_' + ( config.enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' )] )( element );
elementMigrateFilter( config[ 'format_' + ( config.enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) ] )( element );
}
},

Expand Down Expand Up @@ -957,11 +987,22 @@
// Migrate basic style formats to editor configured ones.
b: elementMigrateFilter( config.coreStyles_bold ),
i: elementMigrateFilter( config.coreStyles_italic ),
u: elementMigrateFilter( config.coreStyles_underline ),
s: elementMigrateFilter( config.coreStyles_strike ),
sup: elementMigrateFilter( config.coreStyles_superscript ),
sub: elementMigrateFilter( config.coreStyles_subscript ),

// Move <s> and <u> close to the text elements so other styles (like color) will be applied also
// on underline and strike. Call `elementMigrateFilter` on elements which were not moved (#12750).
s: function( element ) {
if ( !moveToText( element ) ) {
elementMigrateFilter( config.coreStyles_strike )( element );
}
},
u: function( element ) {
if ( !moveToText( element ) ) {
elementMigrateFilter( config.coreStyles_underline )( element );
}
},

// Remove full paths from links to anchors.
a: function( element ) {
var attrs = element.attributes;
Expand Down
185 changes: 185 additions & 0 deletions tests/plugins/pastefromword/movetotext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/* bender-tags: editor,unit */
/* bender-ckeditor-plugins: pastefromword,toolbar,basicstyles,font,colorbutton */
/* bender-include: %BASE_PATH%plugins/clipboard/_helpers/pasting.js */
/* global assertPasteEvent */

( function() {
'use strict';

var editorsDefinitions = {
classic: {
name: 'classic',
config: {
pasteFromWordRemoveFontStyles: false,
allowedContent: true
}
},
customStyle: {
name: 'customStyle',
config: {
pasteFromWordRemoveFontStyles: false,
coreStyles_strike: {
element: 'sub',
overrides: 'strike'
},
coreStyles_underline: {
element: 'sup',
overrides: 'underline'
},
allowedContent: true
}
}
};

function createPasteTest( editor, input, output ) {
return function() {
assertPasteEvent( editor, { dataValue: input }, { dataValue: output }, '', true );
};
}

// jscs:disable maximumLineLength
bender.tools.setUpEditors( editorsDefinitions, function( editors ) {
bender.test( {
'test strike': createPasteTest(
editors.classic,
// Input
'<p class="MsoNormal"><s>foo<o:p></o:p></s></p>',
// Output
'<p><s>foo</s></p>'
),

'test underline': createPasteTest(
editors.classic,
// Input
'<p class="MsoNormal"><u>foo<o:p></o:p></u></p>',
// Output
'<p><u>foo</u></p>'
),

'test strike, underline': createPasteTest(
editors.classic,
// Input
'<p class="MsoNormal"><s><u>foo<o:p></o:p></u></s></p>',
// Output
'<p><s><u>foo</u></s></p>'
),
'test strike, color': createPasteTest(
editors.classic,
// Input
'<p class="MsoNormal"><s><span style="color:red">foo<o:p></o:p></span></s></p>',
// Output
'<p><span style="color:red;"><s>foo</s></span></p>'
),

'test underline, color': createPasteTest(
editors.classic,
// Input
'<p class="MsoNormal"><u><span style="color:red">foo<o:p></o:p></span></u></p>',
// Output
'<p><span style="color:red;"><u>foo</u></span></p>'
),

'test strike, underline, color': createPasteTest(
editors.classic,
// Input
'<p class="MsoNormal"><s><u><span style="color:red">foo<o:p></o:p></span></u></s></p>',
// Output
'<p><span style="color:red;"><s><u>foo</u></s></span></p>'
),
'test strike, color, font, size, bold': createPasteTest(
editors.classic,
// Input
'<p class="MsoNormal"><b><s><span style="font-size:22.2pt;line-height:107%;font-family:&quot;Comic Sans MS&quot;;\ncolor:red">foo<o:p></o:p></span></s></b></p>',
// Output
'<p><strong><span style="color:red;"><span style="font-family:comic sans ms;"><span style="font-size:22.2pt;"><s>foo</s></span></span></span></strong></p>'
),

'test underline, color, font, size, bold': createPasteTest(
editors.classic,
// Input
'<p class="MsoNormal"><b><u><span style="font-size:22.2pt;line-height:107%;font-family:&quot;Comic Sans MS&quot;;\ncolor: red">foo<o:p></o:p></span></u></b></p>',
// Output
'<p><strong><span style="color:red;"><span style="font-family:comic sans ms;"><span style="font-size:22.2pt;"><u>foo</u></span></span></span></strong></p>'
),

'test strike, underline, color, font, size, bold': createPasteTest(
editors.classic,
// Input
'<p class="MsoNormal"><b><s><u><span style="font-size:22.2pt;line-height:107%;font-family:&quot;Comic Sans MS&quot;;\ncolor: red">foo<o:p></o:p></span></u></s></b></p>',
// Output
'<p><strong><span style="color:red;"><span style="font-family:comic sans ms;"><span style="font-size:22.2pt;"><s><u>foo</u></s></span></span></span></strong></p>'
),

'test empty paragraph end, strike, underline, color': createPasteTest(
editors.classic,
// Input
'<p class="MsoNormal"><s><u><span style="color:red">Foo<o:p></o:p></span></u></s></p>' +
'<p class="MsoNormal"><s><u><span style="color:red">&nbsp;</span></u></s></p>' +
'<p class="MsoNormal"><s><u><span style="color:red">bar<o:p></o:p></span></u></s></p>',
// Output
'<p><span style="color:red;"><s><u>Foo</u></s></span></p>' +
'<p>&nbsp;</p>' +
'<p><span style="color:red;"><s><u>bar</u></s></span></p>'
),

'test empty paragraph middle, strike, underline, color': createPasteTest(
editors.classic,
// Input
'<p class="MsoNormal"><s><u><span style="color:red">Foo<o:p></o:p></span></u></s></p>' +
'<p class="MsoNormal"><s><u><span style="color:red">&nbsp;</span></u></s></p>',
// Output
'<p><span style="color:red;"><s><u>Foo</u></s></span></p>' +
'<p>&nbsp;</p>'
),

'test two colors, strike, underline': createPasteTest(
editors.classic,
// Input
'<p class="MsoNormal"><s><u><span style="color:red">Foo </span><span style="color:green">bar</span><span style="color:red"><o:p></o:p></span></u></s></p>',
// Output
'<p><span style="color:red;"><s><u>Foo </u></s></span><span style="color:green;"><s><u>bar</u></s></span><span style="color:red;"></span></p>'
),

'test customStyle, strike': createPasteTest(
editors.customStyle,
// Input
'<p class="MsoNormal"><s>foo<o:p></o:p></s></p>',
// Output
'<p><sub>foo</sub></p>'
),

'test customStyle, underline': createPasteTest(
editors.customStyle,
// Input
'<p class="MsoNormal"><u>foo<o:p></o:p></u></p>',
// Output
'<p><sup>foo</sup></p>'
),

'test customStyle, strike, color': createPasteTest(
editors.customStyle,
// Input
'<p class="MsoNormal"><s><span style="color:red">foo<o:p></o:p></span></s></p>',
// Output
'<p><span style="color:red;"><sub>foo</sub></span></p>'
),

'test customStyle, underline, color': createPasteTest(
editors.customStyle,
// Input
'<p class="MsoNormal"><u><span style="color:red">foo<o:p></o:p></span></u></p>',
// Output
'<p><span style="color:red;"><sup>foo</sup></span></p>'
),

'test customStyle, strike, underline, color, font, size, bold': createPasteTest(
editors.customStyle,
// Input
'<p class="MsoNormal"><b><s><u><span style="font-size:22.2pt;line-height:107%;font-family:&quot;Comic Sans MS&quot;;\ncolor:red">foo<o:p></o:p></span></u></s></b></p>',
// Output
'<p><strong><span style="color:red;"><span style="font-family:comic sans ms;"><span style="font-size:22.2pt;"><sub><sup>foo</sup></sub></span></span></span></strong></p>'
)
} );
} );
// jscs:enable
} )();

0 comments on commit a5f8c73

Please sign in to comment.