From 1b675dd096c8bdd7784cb8be941d24a8da949af8 Mon Sep 17 00:00:00 2001 From: Steve Orvell Date: Tue, 28 Jan 2014 17:07:25 -0800 Subject: [PATCH] support round-tripping --- x-dom-serializer.html | 54 ++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/x-dom-serializer.html b/x-dom-serializer.html index b8b33d4..1e2c69e 100644 --- a/x-dom-serializer.html +++ b/x-dom-serializer.html @@ -12,10 +12,10 @@ tab: ' ', dumpTag: function(node, indent) { if (node.dumpTag) { - return node.dumpTag(this.dumpTab, indent, TAB); + return node.dumpTag(this.dumpTab, indent, this.tab); } if (node.nodeType == Node.TEXT_NODE) { - return this.dumpTextNode(node); + return this.dumpTextNode(node, indent); } var html = ''; html += indent + '<' + node.localName; @@ -31,8 +31,9 @@ if (node.meta && node.meta.hideSubtree) { html += end; } else { - if (node.firstElementChild) { - Array.prototype.forEach.call(node.children, function(c, i) { + var root = node.content || node; + if (root.firstElementChild) { + Array.prototype.forEach.call(root.children, function(c, i) { if (i == 0) { html += '\n'; } @@ -40,8 +41,8 @@ }, this); html += indent + end; } else { - html += node.firstChild ? this.dumpTextNode(node.firstChild) + end - : end; + html += root.firstChild ? this.dumpTextNode(root.firstChild, indent) + + end : end; } } return html; @@ -97,7 +98,8 @@