-
-
Save tallykatt/7886985b505b484c303858bec6947fb1 to your computer and use it in GitHub Desktop.
JSON viewer hack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function codify() { | |
$('span:contains("{")').each(function() { | |
var text = $(this).ignore().text(); | |
var nodes = $(this).find("*").clone(); | |
var res = text.replace(/(\{.+\})/, function (x) { | |
var s = '</span><code class="lang-json">'; | |
s += "" + x + ""; | |
s += '</code><br><span class="non-code">'; | |
return '<span class="non-code">' + s + '</span>'; | |
}); | |
$(this).html(res); | |
}); | |
} | |
function jsonViewify() { | |
$('code.lang-json').each(function() { | |
console.log("jsoncode: ", this); | |
var code_node = $(this); | |
var jsStr = code_node.text(); | |
try { | |
var json = JSON.parse(jsStr); | |
$(this).JSONView(json, { collapsed: true }); | |
} catch (e) { | |
console.error("parsing bug", e); | |
}; | |
}); | |
}; | |
function jsonHackRun() { | |
if (typeof $.fn.ignore === "undefined") { | |
$.fn.ignore = function(sel){ | |
return this.clone().find(sel||">*").remove().end(); | |
}; | |
} | |
codify(); | |
jsonViewify(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment