X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/a5b0d5944c60f5335668c2873f44d9885e745ba0..091b7b5:/src/wlxml/wlxml.js diff --git a/src/wlxml/wlxml.js b/src/wlxml/wlxml.js index 1837e14..989fe5d 100644 --- a/src/wlxml/wlxml.js +++ b/src/wlxml/wlxml.js @@ -239,7 +239,9 @@ $.extend(WLXMLDocument.prototype, { }); nativeNode.normalize(); $(nativeNode).find('*').each(function() { - if (this.childNodes.length === 0) { + 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); } @@ -253,8 +255,7 @@ $.extend(WLXMLDocument.prototype, { elParent = el.parent(), hasSpanParent = elParent.prop('tagName') === 'SPAN', hasSpanBefore = el.prev().length && $(el.prev()).prop('tagName') === 'SPAN', - hasSpanAfter = el.next().length && $(el.next()).prop('tagName') === 'SPAN', - onlyChild = el.is(':only-child'); + hasSpanAfter = el.next().length && $(el.next()).prop('tagName') === 'SPAN'; var addInfo = function(toAdd, where, transformed, original) { @@ -295,7 +296,7 @@ $.extend(WLXMLDocument.prototype, { } } - if(!text.transformed && !onlyChild) { + if(!text.transformed && !(el.is(':only-child') || (el.is(':last-child') && hasSpanBefore))) { addInfo(text.original, 'below'); el.remove(); return true; // continue