-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsonHighlighter.min.js
11 lines (11 loc) · 1.29 KB
/
jsonHighlighter.min.js
1
2
3
4
5
6
7
8
9
10
11
/*
* JSON Highlight : Small JSON highlighter for your webpage.
* http://github.com/cope/jsonHighlight/
*
* Licensed under the MIT licenses.
*
* Inspired by (read: stolen from) http://stackoverflow.com/a/7220510
* Therefore, all credit goes to Pumbaa80 (http://stackoverflow.com/users/27862/pumbaa80)
*
*/
cope="undefined"===typeof cope?{}:cope;cope.Highlighter="undefined"===typeof cope.Highlighter?{}:cope.Highlighter;cope.Highlighter.cssString="color: darkgreen;";cope.Highlighter.cssNumber="color: darkorange;";cope.Highlighter.cssBoolean="color: blue;";cope.Highlighter.cssNull="color: magenta;";cope.Highlighter.cssKey="color: red;"; cope.Highlighter.highlight=function(a,b){var c=2,d=!1;b&&(b.indent&&(c=b.indent),b.useTabs&&(d=b.useTabs));a="string"!=typeof a?JSON.stringify(a,void 0,!0===d?"\t":c):JSON.stringify(JSON.parse(a),void 0,!0===d?"\t":c);a=a.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");return a.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,function(a){var b=cope.Highlighter.cssNumber;/^"/.test(a)?b=/:$/.test(a)?cope.Highlighter.cssKey:cope.Highlighter.cssString: /true|false/.test(a)?b=cope.Highlighter.cssBoolean:/null/.test(a)&&(b=cope.Highlighter.cssNull);return'<span style="'+b+'">'+a+"</span>"})};