Last active
July 25, 2016 01:57
-
-
Save elcritch/8d9217f0f33c3010819fb04b6f8b7199 to your computer and use it in GitHub Desktop.
JSON viewer hack
This file contains 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