From 9eacfb7b22dd90e9da9575c5f0d007896ff68440 Mon Sep 17 00:00:00 2001 From: "kyuwoo.choi" Date: Thu, 20 Apr 2017 10:31:52 +0900 Subject: [PATCH] fix: handle insert table by CF_HTML ms html clipboard format CF_HTML handles table like below if we copy part of table. it makes problem when copying table from ms product such as ie, excel, powerpoint then pasting to squire.
Item 6Item 7
Item 10Item 11
and
Item
https://msdn.microsoft.com/en-us/library/windows/desktop/ms649015(v=vs.85).aspx #274 --- source/Editor.js | 8 ++++++++ test/squire.spec.js | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/source/Editor.js b/source/Editor.js index f0c9a19..86eb771 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -1749,6 +1749,14 @@ proto.insertHTML = function ( html, isPaste ) { } // Parse HTML into DOM tree div = this.createElement( 'DIV' ); + // wrap with tr if html contains dangling td tags + if (html.match(/<\/td>((?!<\/tr>)[\s\S])*$/i)) { + html = '' + html + ''; + } + // wrap with table if html contains dangling tr tags + if (html.match(/<\/tr>((?!<\/table>)[\s\S])*$/i)) { + html = '' + html + '
'; + } div.innerHTML = html; frag = doc.createDocumentFragment(); frag.appendChild( empty( div ) ); diff --git a/test/squire.spec.js b/test/squire.spec.js index a832ee0..fc6794b 100644 --- a/test/squire.spec.js +++ b/test/squire.spec.js @@ -351,6 +351,18 @@ describe('Squire RTE', function () { }) }); + describe('insertHTML', function() { + it('fix CF_HTML incomplete table', function() { + editor.insertHTML('
text
'); + expect(editor.getHTML(), 'to contain', '
text
'); + + editor.setHTML(''); + + editor.insertHTML('
text1text2
'); + expect(editor.getHTML(), 'to contain', '
text1
text2
'); + }); + }); + afterEach(function () { editor = null; var iframe = document.getElementById('testFrame');