Strange, works fine for me.
Can you try this snippet in a new JS Query:
var initElement = richTextEditor1.value;
var json = mapDOM(initElement, true);
console.log(json);
return json;
function mapDOM(element, json) {
var treeObject = {};
// If string convert to document Node
if (typeof element === "string") {
if (window.DOMParser) {
parser = new DOMParser();
docNode = parser.parseFromString(element, "text/xml");
} // Microsoft strikes again
else {
docNode = new ActiveXObject("Microsoft.XMLDOM");
docNode.async = false;
docNode.loadXML(element);
}
element = docNode.firstChild;
}
//Recursively loop through DOM elements and assign properties to object
function treeHTML(element, object) {
object["type"] = element.nodeName;
var nodeList = element.childNodes;
if (nodeList != null) {
if (nodeList.length) {
object["content"] = [];
for (var i = 0; i < nodeList.length; i++) {
if (nodeList[i].nodeType == 3) {
object["content"].push(nodeList[i].nodeValue);
} else {
object["content"].push({});
treeHTML(
nodeList[i],
object["content"][object["content"].length - 1]
);
}
}
}
}
if (element.attributes != null) {
if (element.attributes.length) {
object["attributes"] = {};
for (var i = 0; i < element.attributes.length; i++) {
object["attributes"][element.attributes[i].nodeName] =
element.attributes[i].nodeValue;
}
}
}
}
treeHTML(element, treeObject);
return json ? JSON.stringify(treeObject) : treeObject;
}