Permalink
Browse files

Added support for pasting from Excel

  • Loading branch information...
mlewand committed Apr 21, 2017
2 parents 191a21f + f3ac54a commit 7f51a45515b4d5a76a206f2a24a5acf0daa9ce0b
Showing with 1,693 additions and 13 deletions.
  1. +1 −0 CHANGES.md
  2. +49 −12 plugins/pastefromword/filter/default.js
  3. BIN tests/plugins/pastefromword/generated/_fixtures/Table_text_attributes/Cell_text/Cell_text.xlsx
  4. +87 −0 ...ins/pastefromword/generated/_fixtures/Table_text_attributes/Cell_text/excel2013/datatransfer.html
  5. +15 −0 ...ins/pastefromword/generated/_fixtures/Table_text_attributes/Cell_text/excel2013/expected_ie8.html
  6. +15 −0 tests/plugins/pastefromword/generated/_fixtures/Table_text_attributes/Cell_text/excel2013/ie8.html
  7. +86 −0 ...ins/pastefromword/generated/_fixtures/Table_text_attributes/Cell_text/excel2016/datatransfer.html
  8. +17 −0 ...ns/pastefromword/generated/_fixtures/Table_text_attributes/Cell_text/excel2016/expected_ie11.html
  9. +9 −0 tests/plugins/pastefromword/generated/_fixtures/Table_text_attributes/Cell_text/excel2016/ie11.html
  10. +42 −0 tests/plugins/pastefromword/generated/_fixtures/Table_text_attributes/Cell_text/expected.html
  11. BIN tests/plugins/pastefromword/generated/_fixtures/Table_text_attributes/Mixed/Mixed.xlsx
  12. +257 −0 ...plugins/pastefromword/generated/_fixtures/Table_text_attributes/Mixed/excel2013/datatransfer.html
  13. +131 −0 ...plugins/pastefromword/generated/_fixtures/Table_text_attributes/Mixed/excel2013/expected_ie8.html
  14. +32 −0 tests/plugins/pastefromword/generated/_fixtures/Table_text_attributes/Mixed/excel2013/ie8.html
  15. +256 −0 ...plugins/pastefromword/generated/_fixtures/Table_text_attributes/Mixed/excel2016/datatransfer.html
  16. +172 −0 ...lugins/pastefromword/generated/_fixtures/Table_text_attributes/Mixed/excel2016/expected_ie11.html
  17. +38 −0 tests/plugins/pastefromword/generated/_fixtures/Table_text_attributes/Mixed/excel2016/ie11.html
  18. +403 −0 tests/plugins/pastefromword/generated/_fixtures/Table_text_attributes/Mixed/expected.html
  19. +2 −1 tests/plugins/pastefromword/generated/_helpers/pfwTools.js
  20. +55 −0 tests/plugins/pastefromword/generated/excel.js
  21. +7 −0 tests/plugins/pastefromword/manual/pastefromexcel.html
  22. +19 −0 tests/plugins/pastefromword/manual/pastefromexcel.md
View
@@ -9,6 +9,7 @@
New Features:
* [#16961](http://dev.ckeditor.com/ticket/16961): Added a support for pasting from Excel.
* [#16971](http://dev.ckeditor.com/ticket/16971): Added a support for color in `background` property containing also other styles for table cells in [Table Tools](http://ckeditor.com/addon/tabletools) plugin.
* [#16847](http://dev.ckeditor.com/ticket/16847): Added a support for parsing and inlining any formatting created using Microsoft Word's style system to the [Paste from Word](http://ckeditor.com/addon/pastefromword) plugin.
* [#16818](http://dev.ckeditor.com/ticket/16818): Added table cell height parsing in the [Paste from Word](http://ckeditor.com/addon/pastefromword) plugin.
@@ -205,7 +205,15 @@
delete element.attributes.size;
}
createAttributeStack( element, filter );
// Create style stack for td/th > font if only class
// and style attributes are present. Such markup is produced by Excel.
if ( CKEDITOR.dtd.tr[ element.parent.name ] &&
CKEDITOR.tools.arrayCompare( CKEDITOR.tools.objectKeys( element.attributes ), [ 'class', 'style' ] ) ) {
Style.createStyleStack( element, filter, editor );
} else {
createAttributeStack( element, filter );
}
},
'ul': function( element ) {
if ( !msoListsDetected ) {
@@ -341,9 +349,8 @@
}
}
Style.pushStylesLower( element, {
'background': true
} );
Style.createStyleStack( element, filter, editor,
/margin|text\-align|padding|list\-style\-type|width|height|border|white\-space|vertical\-align|background/i );
},
'v:imagedata': remove,
// This is how IE8 presents images.
@@ -386,7 +393,8 @@
return Style.normalizedStyles( element, editor ) || false;
},
'class': function( classes ) {
return falseIfEmpty( classes.replace( /msonormal|msolistparagraph\w*/ig, '' ) );
// The (el\d+)|(font\d+) are default Excel classes for table cells and text.
return falseIfEmpty( classes.replace( /(el\d+)|(font\d+)|msonormal|msolistparagraph\w*/ig, '' ) );
},
'cellspacing': remove,
'cellpadding': remove,
@@ -421,6 +429,7 @@
var writer = new CKEDITOR.htmlParser.basicWriter();
filter.applyTo( fragment );
fragment.writeHtml( writer );
return writer.getHtml();
@@ -549,9 +558,11 @@
* @param {CKEDITOR.htmlParser.element} element
* @param {CKEDITOR.htmlParser.filter} filter
* @param {CKEDITOR.editor} editor
* @param {RegExp} [skipStyles] All matching style names will not be extracted to a style stack. Defaults
* to `/margin|text\-align|width|border|padding/i`.
* @member CKEDITOR.plugins.pastefromword.styles
*/
createStyleStack: function( element, filter, editor ) {
createStyleStack: function( element, filter, editor, skipStyles ) {
var children = [],
i;
@@ -571,7 +582,7 @@
styleTopmost = element.name === 'span'; // Ensure that the root element retains at least one style.
for ( var style in styles ) {
if ( style.match( /margin|text\-align|width|border|padding/i ) ) {
if ( style.match( skipStyles || /margin|text\-align|width|border|padding/i ) ) {
continue;
}
@@ -644,9 +655,18 @@
element.attributes.style = CKEDITOR.tools.writeCssText( sortedStyles );
},
// Moves the element's styles lower in the DOM hierarchy.
// Returns true on success.
pushStylesLower: function( element, exceptions ) {
/**
* Moves the element's styles lower in the DOM hierarchy. If wrapText==true and the direct child of an element
* is a text node it will be wrapped in a `span` element.
*
* @param {CKEDITOR.htmlParser.element} element
* @param {Object} exceptions Object containing style names which should not be moved, e.g. `{ background: true }`.
* @param {Boolean} [wrapText=false] Whether a direct text child of an element should be wrapped into a `span` tag
* so that the styles can be moved to it.
* @returns {Boolean} Returns true if styles were successfully moved lower.
*/
pushStylesLower: function( element, exceptions, wrapText ) {
if ( !element.attributes.style ||
element.children.length === 0 ) {
return false;
@@ -678,6 +698,13 @@
for ( var i = 0; i < element.children.length; i++ ) {
var child = element.children[ i ];
if ( child.type === CKEDITOR.NODE_TEXT && wrapText ) {
var wrapper = new CKEDITOR.htmlParser.element( 'span' );
wrapper.setHtml( child.value );
child.replaceWith( wrapper );
child = wrapper;
}
if ( child.type !== CKEDITOR.NODE_ELEMENT ) {
continue;
}
@@ -850,17 +877,27 @@
styleText = CKEDITOR.tools.writeCssText( style );
if ( element.getAttribute( 'style' ) ) {
styleText += ';' + element.getAttribute( 'style' );
styleText = element.getAttribute( 'style' ) + ';' + styleText;
}
element.setAttribute( 'style', styleText );
}
}
function applyStyles( document, styles ) {
var style;
var classStyles = {},
style;
for ( style in styles ) {
if ( style.substr( 0, 1 ) === '.' ) {
classStyles[ style ] = styles[ style ];
} else {
applyStyle( document, style, styles[ style ] );
}
}
// Workaround for #16957.
for ( style in classStyles ) {
applyStyle( document, style, styles[ style ] );
}
}
@@ -0,0 +1,87 @@
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 15">
<link id=Main-File rel=Main-File
href="file:///C:\Users\foobar\AppData\Local\Temp\msohtmlclip1\01\clip.htm">
<link rel=File-List
href="file:///C:\Users\foobar\AppData\Local\Temp\msohtmlclip1\01\clip_filelist.xml">
<style>
<!--table
{mso-displayed-decimal-separator:"\.";
mso-displayed-thousand-separator:"\,";}
@page
{margin:.75in .7in .75in .7in;
mso-header-margin:.3in;
mso-footer-margin:.3in;}
.font5
{color:#002060;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;}
.font6
{color:#002060;
font-size:8.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;}
tr
{mso-height-source:auto;}
col
{mso-width-source:auto;}
br
{mso-data-placement:same-cell;}
td
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
border:none;
mso-background-source:auto;
mso-pattern:auto;
mso-protection:locked visible;
white-space:nowrap;
mso-rotate:0;}
.xl65
{color:#00B0F0;
border:.5pt solid windowtext;}
-->
</style>
</head>
<body link="#0563C1" vlink="#954F72">
<table border=0 cellpadding=0 cellspacing=0 width=282 style='border-collapse:
collapse;width:212pt'>
<col width=282 style='mso-width-source:userset;mso-width-alt:10313;width:212pt'>
<tr height=20 style='height:15.0pt'>
<!--StartFragment-->
<td height=20 class=xl65 width=282 style='height:15.0pt;width:212pt'>color on
text <font class="font5">and row </font><font class="font6">and size</font></td>
<!--EndFragment-->
</tr>
</table>
</body>
</html>
@@ -0,0 +1,15 @@
<table cellspacing="0" style="width:212pt">
<tbody>
<tr>
<td style="height:15pt; width:212pt">
<span style="font-size:medium">
<span style="color:#00b0f0">color on text </span>
<span style="color:#002060">and row </span>
</span>
<span style="color:#002060">
<span style="font-size:small">and size</span>
</span>
</td>
</tr>
</tbody>
</table>
@@ -0,0 +1,15 @@
<TABLE style="WIDTH: 212pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=282>
<COLGROUP>
<COL style="WIDTH: 212pt; mso-width-source: userset; mso-width-alt: 10313" width=282>
<TBODY>
<TR style="HEIGHT: 15pt" height=20>
<TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 212pt; HEIGHT: 15pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl63 height=20 width=282>
<FONT size=3>
<FONT color=#00b0f0>color on text </FONT>
<FONT class=font5 color=#002060>and row </FONT>
</FONT>
<FONT class=font6 color=#002060 size=2>and size</FONT>
</TD>
</TR>
</TBODY>
</TABLE>
@@ -0,0 +1,86 @@
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 15">
<link id=Main-File rel=Main-File
href="file:///C:/Users/IEUser/AppData/Local/Temp/msohtmlclip1/01/clip.htm">
<link rel=File-List
href="file:///C:/Users/IEUser/AppData/Local/Temp/msohtmlclip1/01/clip_filelist.xml">
<style>
<!--table
{mso-displayed-decimal-separator:"\.";
mso-displayed-thousand-separator:"\,";}
@page
{margin:.75in .7in .75in .7in;
mso-header-margin:.3in;
mso-footer-margin:.3in;}
.font5
{color:#002060;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;}
.font6
{color:#002060;
font-size:8.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;}
tr
{mso-height-source:auto;}
col
{mso-width-source:auto;}
br
{mso-data-placement:same-cell;}
td
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
border:none;
mso-background-source:auto;
mso-pattern:auto;
mso-protection:locked visible;
white-space:nowrap;
mso-rotate:0;}
.xl63
{color:#00B0F0;
border:.5pt solid windowtext;}
-->
</style>
</head>
<body link="#0563C1" vlink="#954F72">
<table border=0 cellpadding=0 cellspacing=0 width=282 style='border-collapse:
collapse;width:212pt'>
<col width=282 style='mso-width-source:userset;mso-width-alt:10313;width:212pt'>
<tr height=20 style='height:15.0pt'>
<!--StartFragment-->
<td height=20 class=xl63 width=282 style='height:15.0pt;width:212pt'>color on
text <font class="font5">and row </font><font class="font6">and size</font></td>
<!--EndFragment-->
</tr>
</table>
</body>
</html>
@@ -0,0 +1,17 @@
<table border="1" cellspacing="0" style="width:212pt">
<tbody>
<tr>
<td style="height:15pt; width:212pt">
<span style="font-family:calibri">
<span style="font-size:medium">
<span style="color:#00b0f0">color on text </span>
<span style="color:#002060">and row </span>
</span>
<span style="color:#002060">
<span style="font-size:small">and size</span>
</span>
</span>
</td>
</tr>
</tbody>
</table>
@@ -0,0 +1,9 @@
<table width="282" style="width: 212pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0"><font color="#000000" face="Times New Roman" size="3">
</font><colgroup><col width="282" style="width: 212pt; mso-width-source: userset; mso-width-alt: 10313;"><font color="#000000" face="Times New Roman" size="3">
</font><tbody><tr height="20" style="height: 15pt;"><font color="#000000" face="Times New Roman" size="3">
</font><td width="282" height="20" style="border: 0.5pt solid windowtext; width: 212pt; height: 15pt; background-color: transparent;"><font face="Calibri"><font size="3"><font color="#00b0f0">color on
text </font><font color="#002060">and row </font></font><font color="#002060" size="2">and size</font></font></td><font color="#000000" face="Times New Roman" size="3">
</font></tr><font color="#000000" face="Times New Roman" size="3">
</font></tbody></table>
Oops, something went wrong.

0 comments on commit 7f51a45

Please sign in to comment.