1 // Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
2 // Copyright (c) 2008-2012 Kris Maglione <maglione.k@gmail.com>
4 // This work is licensed for reuse under an MIT license. Details are
5 // given in the LICENSE.txt file included with this file.
12 lazyRequire("highlight", ["highlight"]);
14 var XBL = Namespace("xbl", "http://www.mozilla.org/xbl");
15 var XHTML = Namespace("html", "http://www.w3.org/1999/xhtml");
16 var XUL = Namespace("xul", "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
17 var NS = Namespace("dactyl", "http://vimperator.org/namespaces/liberator");
19 function fromXML(node, doc, nodes) {
20 XML.ignoreWhitespace = XML.prettyPrinting = false;
21 if (typeof node === "string") // Sandboxes can't currently pass us XML objects.
24 if (node.length() != 1) {
25 let domnode = doc.createDocumentFragment();
26 for each (let child in node)
27 domnode.appendChild(fromXML(child, doc, nodes));
31 switch (node.nodeKind()) {
33 return doc.createTextNode(String(node));
35 let domnode = doc.createElementNS(node.namespace(), node.localName());
37 for each (let attr in node.@*::*)
38 if (attr.name() != "highlight")
39 domnode.setAttributeNS(attr.namespace(), attr.localName(), String(attr));
41 for each (let child in node.*::*)
42 domnode.appendChild(fromXML(child, doc, nodes));
43 if (nodes && node.@key)
44 nodes[node.@key] = domnode;
46 if ("@highlight" in node)
47 highlight.highlightNode(domnode, String(node.@highlight), nodes || true);
54 // vim: set fdm=marker sw=4 sts=4 ts=8 et ft=javascript: