Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paste from word now respect enter_br mode #826

Merged
merged 10 commits into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Fixed Issues:
* [#554](https://github.com/ckeditor/ckeditor-dev/issues/554): Fixed: [`change`](https://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-change) event not fired when typing the first character after pasting into the editor. Thanks to [Daniel Miller](https://github.com/millerdev)!
* [#566](https://github.com/ckeditor/ckeditor-dev/issues/566): Fixed: The CSS border shorthand property with zero width (`border: 0px solid #000;`) no longer causes table to have border attribute set to 1.
* [#779](https://github.com/ckeditor/ckeditor-dev/issues/779): Fixed: [Remove Format](https://ckeditor.com/addon/removeformat) plugin removes elements with language definition inserted by [Language](https://ckeditor.com/addon/language) plugin.
* [#423](https://github.com/ckeditor/ckeditor-dev/issues/423): Fixed: [Paste from Word](https://ckeditor.com/addon/pastefromword) plugin pastes paragraphs into the editor even if [`CKEDITOR.config.enterMode`](https://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-enterMode) is set to `CKEDITOR.ENTER_BR`.

## CKEditor 4.7.2

Expand Down
8 changes: 8 additions & 0 deletions plugins/pastefromword/filter/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@
style[ 'mso-list' ].match( /level/ ) ) {
container.attributes[ 'cke-list-level' ] = style[ 'mso-list' ].match( /level(\d+)/ )[1];
}

// Adapt paragraph formatting to editor's convention according to enter-mode (#423).
if ( editor.config.enterMode == CKEDITOR.ENTER_BR ) {
// We suffer from attribute/style lost in this situation.
delete element.name;
element.add( new CKEDITOR.htmlParser.element( 'br' ) );
}

}

Style.createStyleStack( element, filter, editor );
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<strong><em>Paste from Word<br />Next</em></strong><br />
<strong><em>Totally new</em></strong>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<font color="#000000" face="Times New Roman" size="3">

</font><p style="margin: 0in 0in 8pt;"><b style="mso-bidi-font-weight: normal;"><i style="mso-bidi-font-style: normal;"><font face="Calibri"><font color="#000000" size="3">Paste from word<br></font><font color="#000000" size="3">
Next</font></font></i></b></p><font color="#000000" face="Times New Roman" size="3">

</font><p style="margin: 0in 0in 8pt;"><b style="mso-bidi-font-weight: normal;"><i style="mso-bidi-font-style: normal;"><font color="#000000" face="Calibri" size="3">Totally new</font></i></b></p><font color="#000000" face="Times New Roman" size="3">

</font>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<P style="MARGIN: 0in 0in 8pt" class=MsoNormal><B style="mso-bidi-font-weight: normal"><I style="mso-bidi-font-style: normal"><FONT size=3><FONT color=#000000>Paste from word<BR>Next<o:p></o:p></FONT></FONT></I></B></P>
<P style="MARGIN: 0in 0in 8pt" class=MsoNormal><B style="mso-bidi-font-weight: normal"><I style="mso-bidi-font-style: normal"><FONT size=3><FONT color=#000000>Totally new<o:p></o:p></FONT></FONT></I></B></P>
39 changes: 39 additions & 0 deletions tests/plugins/pastefromword/generated/enter_br.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* bender-tags: clipboard,pastefromword */
/* jshint ignore:start */
/* bender-ckeditor-plugins: pastefromword,ajax,basicstyles,toolbar */
/* jshint ignore:end */
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js */
/* bender-include: _helpers/createTestSuite.js */
/* global createTestSuite */

( function() {
'use strict';

var config = {
language: 'en',
colorButton_normalizeBackground: false,
allowedContent: 'p strong em',
enterMode: CKEDITOR.ENTER_BR
};

bender.editor = {
config: config
};

bender.test( createTestSuite( {
browsers: [
'chrome',
'firefox',
'ie11',
'ie8'
],
wordVersions: [
'word2016'
],
tests: {
'Enter_BR': true
},

compareRawData: false
} ) );
} )();
9 changes: 9 additions & 0 deletions tests/plugins/pastefromword/manual/enterbr.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<textarea cols="80" id="editor1" name="editor1" rows="10">
Hello World
</textarea>
<script>
var editor = CKEDITOR.replace( 'editor1', {
enterMode: CKEDITOR.ENTER_BR,
extraAllowedContent: 'p'
} );
</script>
14 changes: 14 additions & 0 deletions tests/plugins/pastefromword/manual/enterbr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@bender-tags: bug, 4.7.3, word
@bender-ui: collapsed
@bender-ckeditor-plugins: pastefromword,toolbar,basicstyles,enterkey,wysiwygarea,sourcearea

----
1. Open [docx file](../generated/_fixtures/Enter_BR/Enter_BR.docx) in Microsft Word.
1. Copy text from file and paste it to editor.
1. Check Source in editor.

**Expected:** There is no `<p>` tags in source. Every paragraph is replaced with `<br />`.

**Unexpected:** There are `<p>` tag after paste.