X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/e789468531597875c9c171d0554230856d40a2b9..d13ac0186f86e208dc64e43b773576c5a224ad07:/src/wlxml/wlxml.js diff --git a/src/wlxml/wlxml.js b/src/wlxml/wlxml.js index 40ab196..d05eb64 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,12 @@ $.extend(WLXMLDocument.prototype, { metadataNode.remove(); }); nativeNode.normalize(); + $(nativeNode).find('*').each(function() { + if (this.childNodes.length === 0) { + var fakeTextNode = window.document.createTextNode(""); + this.appendChild(fakeTextNode); + } + }); $(nativeNode).find(':not(iframe)').addBack().contents() .filter(function() {return this.nodeType === Node.TEXT_NODE;}) @@ -235,7 +253,8 @@ $.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'; + hasSpanAfter = el.next().length && $(el.next()).prop('tagName') === 'SPAN', + onlyChild = el.is(':only-child'); var addInfo = function(toAdd, where, transformed, original) { @@ -276,7 +295,7 @@ $.extend(WLXMLDocument.prototype, { } } - if(!text.transformed) { + if(!text.transformed && !onlyChild) { addInfo(text.original, 'below'); el.remove(); return true; // continue