1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-22 02:35:47 +01:00
This commit is contained in:
Kris Maglione
2009-04-22 13:15:56 -04:00
parent 9320c5b1be
commit 2f753b6d27
7 changed files with 46 additions and 21 deletions

View File

@@ -28,7 +28,8 @@ the terms of any one of the MPL, the GPL or the LGPL.
/** @scope modules */
const XHTML = "http://www.w3.org/1999/xhtml";
const XHTML = Namespace("html", "http://www.w3.org/1999/xhtml");
const XUL = Namespace("xul", "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
const NS = Namespace("liberator", "http://vimperator.org/namespaces/liberator");
default xml namespace = XHTML;
@@ -404,6 +405,32 @@ const util = { //{{{
if (typeof object != "object")
return false;
const NAMESPACES = util.Array.toObject([
[NS, 'liberator'],
[XHTML, 'html'],
[XUL, 'xul'],
]);
if (object instanceof Node) {
let elem = object;
if (elem.nodeType == elem.TEXT_NODE)
return elem.data;
function namespaced(node) {
var ns = NAMESPACES[node.namespaceURI];
if (ns)
return ns + ":" + node.localName;
return node.localName.toLowerCase();
}
let tag = "<" + [namespaced(elem)].concat(
[namespaced(a) + "=" + template.highlight(a.value, true)
for ([i, a] in util.Array.iteritems(elem.attributes))]).join(" ");
if (!elem.firstChild || /^\s*$/.test(elem.firstChild) && !elem.firstChild.nextSibling)
tag += '/>';
else
tag += '>...</' + namespaced(elem) + '>';
return tag;
}
try
{ // for window.JSON
var obj = String(object);