summaryrefslogtreecommitdiff
path: root/share/www/script/futon.format.js
diff options
context:
space:
mode:
Diffstat (limited to 'share/www/script/futon.format.js')
-rw-r--r--share/www/script/futon.format.js24
1 files changed, 15 insertions, 9 deletions
diff --git a/share/www/script/futon.format.js b/share/www/script/futon.format.js
index 5feee817..8d9b7f5c 100644
--- a/share/www/script/futon.format.js
+++ b/share/www/script/futon.format.js
@@ -13,6 +13,14 @@
(function($) {
$.futon = $.futon || {};
$.extend($.futon, {
+ escape: function(string) {
+ return string.replace(/&/g, "&")
+ .replace(/</g, "&lt;")
+ .replace(/>/g, "&gt;")
+ .replace(/"/, "&quot;")
+ .replace(/'/, "&#39;")
+ ;
+ },
// JSON pretty printing
formatJSON: function(val, options) {
@@ -24,12 +32,6 @@
}, options || {});
var itemsep = options.linesep.length ? "," + options.linesep : ", ";
- function escape(string) {
- return string.replace(/&/g, "&amp;")
- .replace(/</g, "&lt;")
- .replace(/>/g, "&gt;");
- }
-
function format(val, depth) {
var tab = [];
for (var i = 0; i < options.indent * depth; i++) tab.push("");
@@ -44,7 +46,11 @@
if (type == "string" && !options.escapeStrings) {
retval = indentLines(retval.replace(/\r\n/g, "\n"), tab.substr(options.indent));
} else {
- retval = escape(JSON.stringify(val));
+ if (options.html) {
+ retval = $.futon.escape(JSON.stringify(val));
+ } else {
+ retval = JSON.stringify(val);
+ }
}
if (options.html) {
retval = "<code class='" + type + "'>" + retval + "</code>";
@@ -88,7 +94,7 @@
if (options.quoteKeys) {
keyDisplay = keyDisplay.substr(1, keyDisplay.length - 2);
}
- keyDisplay = "<code class='key'>" + escape(keyDisplay) + "</code>";
+ keyDisplay = "<code class='key'>" + $.futon.escape(keyDisplay) + "</code>";
if (options.quoteKeys) {
keyDisplay = '"' + keyDisplay + '"';
}
@@ -114,7 +120,7 @@
function indentLines(text, tab) {
var lines = text.split("\n");
for (var i in lines) {
- lines[i] = (i > 0 ? tab : "") + escape(lines[i]);
+ lines[i] = (i > 0 ? tab : "") + $.futon.escape(lines[i]);
}
return lines.join("<br>");
}