X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/e789468531597875c9c171d0554230856d40a2b9..HEAD:/src/wlxml/wlxml.js diff --git a/src/wlxml/wlxml.js b/src/wlxml/wlxml.js index 40ab196..a5a87d2 100644 --- a/src/wlxml/wlxml.js +++ b/src/wlxml/wlxml.js @@ -44,6 +44,19 @@ var WLXMLDocumentNodeMethods = { } }.bind(this)); return toret; + }, + getContextRoot: function() { + var contextRoot; + [this].concat(this.parents()).some(function(n) { + if(n.isContextRoot()) { + contextRoot = n; + return true; + } + }); + return contextRoot; + }, + hasSameContextRoot: function(other) { + return this.getContextRoot().sameNode(other.getContextRoot()); } }; @@ -183,7 +196,6 @@ var WLXMLDocumentNode = function() { }; WLXMLDocumentNode.prototype = Object.create(smartxml.DocumentNode.prototype); - var WLXMLTextNode = function() { smartxml.TextNode.apply(this, arguments); }; @@ -226,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;}) @@ -237,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]), @@ -276,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