some other minor changes from milpeer
[fnpeditor.git] / src / wlxml / wlxml.js
index d05eb64..a5a87d2 100644 (file)
@@ -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,9 +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) {
                     var parentContents = elParent.contents(),
@@ -295,7 +295,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