Skip to content
Permalink
Browse files

fix: paste cells from excel to table of wysiwyg (close: #420) (#431)

* fix: paste cells from excel to table of wysiwyg (close: #420)

* refactor: more detail comment
  • Loading branch information...
sohee-lee7 committed Mar 11, 2019
1 parent e7cb146 commit cf41d4dd85d44c40f52b002f8013e149694fff9d
Showing with 19 additions and 0 deletions.
  1. +19 −0 src/js/wwTablePasteHelper.js
@@ -106,6 +106,25 @@ class WwTablePasteHelper {
*/
_pasteClipboardHtml(html) {
const container = document.createDocumentFragment();
const startFramgmentStr = '<!--StartFragment-->';
const endFragmentStr = '<!--EndFragment-->';
const startFragmentIndex = html.indexOf(startFramgmentStr);
const endFragmentIndex = html.lastIndexOf(endFragmentStr);

if (startFragmentIndex > -1 && endFragmentIndex > -1) {
html = html.slice(startFragmentIndex + startFramgmentStr.length, endFragmentIndex);
}

// Wrap with <tr> if html contains dangling <td> tags
// Dangling <td> tag is that tag does not have <tr> as parent node.
if (/<\/td>((?!<\/tr>)[\s\S])*$/i.test(html)) {
html = '<TR>' + html + '</TR>';
}
// Wrap with <table> if html contains dangling <tr> tags
// Dangling <tr> tag is that tag does not have <table> as parent node.
if (/<\/tr>((?!<\/table>)[\s\S])*$/i.test(html)) {
html = '<TABLE>' + html + '</TABLE>';
}

container.appendChild(htmlSanitizer(html));
this._pasteClipboardContainer(container);

0 comments on commit cf41d4d

Please sign in to comment.
You can’t perform that action at this time.