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');