X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/e10030e66aab8b55dab8b8ba507a9140243129fa..HEAD:/src/wlxml/wlxml.js diff --git a/src/wlxml/wlxml.js b/src/wlxml/wlxml.js index ef70d3d..a5a87d2 100644 --- a/src/wlxml/wlxml.js +++ b/src/wlxml/wlxml.js @@ -238,6 +238,14 @@ $.extend(WLXMLDocument.prototype, { metadataNode.remove(); }); nativeNode.normalize(); + $(nativeNode).find('*').each(function() { + var emptyNode = this.childNodes.length === 0; + var endsWithSpan = !emptyNode && this.childNodes[this.childNodes.length - 1].nodeName.toLowerCase() === 'span'; + if(emptyNode || endsWithSpan) { + var fakeTextNode = window.document.createTextNode(""); + this.appendChild(fakeTextNode); + } + }); $(nativeNode).find(':not(iframe)').addBack().contents() .filter(function() {return this.nodeType === Node.TEXT_NODE;}) @@ -249,7 +257,6 @@ $.extend(WLXMLDocument.prototype, { hasSpanBefore = el.prev().length && $(el.prev()).prop('tagName') === 'SPAN', hasSpanAfter = el.next().length && $(el.next()).prop('tagName') === 'SPAN'; - var addInfo = function(toAdd, where, transformed, original) { var parentContents = elParent.contents(), idx = parentContents.index(el[0]), @@ -288,7 +295,7 @@ $.extend(WLXMLDocument.prototype, { } } - if(!text.transformed) { + if(!text.transformed && !(el.is(':only-child') || (el.is(':last-child') && hasSpanBefore))) { addInfo(text.original, 'below'); el.remove(); return true; // continue