syntax highlight
diff --git a/planetstack/core/static/shell/opencloud_shell.js b/planetstack/core/static/shell/opencloud_shell.js
index 861cd10..9091353 100644
--- a/planetstack/core/static/shell/opencloud_shell.js
+++ b/planetstack/core/static/shell/opencloud_shell.js
@@ -354,8 +354,39 @@
}
};
+function replaceAll(find, replace, str) {
+ return str.replace(new RegExp(find, 'g'), replace);
+}
+
+/* stackoverflow: http://stackoverflow.com/questions/4810841/how-can-i-pretty-print-json-using-javascript */
+function syntaxHighlight(json) {
+ if ( json.hasOwnProperty("__str__")) {
+ return syntaxHighlight(json.__str__());
+ }
+ if (typeof json != 'string') {
+ json = JSON.stringify(json, undefined, "\t");
+ }
+ json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
+ return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
+ var cls = 'terminal_number';
+ if (/^"/.test(match)) {
+ if (/:$/.test(match)) {
+ cls = 'terminal_key';
+ } else {
+ cls = 'terminal_string';
+ }
+ } else if (/true|false/.test(match)) {
+ cls = 'terminal_boolean';
+ } else if (/null/.test(match)) {
+ cls = 'terminal_null';
+ }
+ return '<span class="' + cls + '">' + match + '</span>';
+ });
+}
+
$htmlFormat = function(obj) {
- result=tojson(obj, ' ', ' ', true);
+ //JSON.stringify(obj,undefined,2)
+ result=replaceAll("\t"," ",replaceAll("\n","<br>",syntaxHighlight(obj))); //tojson(obj, ' ', ' ', true);
return result;
}