Minor playground fix
authorMarkus Lanthaler <mark_lanthaler@gmx.net>
Fri, 05 Apr 2013 12:10:11 +0200
changeset 1547 81563d0565de
parent 1546 b08a2b2e4502
child 1548 0a520c8e1f48
Minor playground fix

Ensures that strings are properly HTML-escaped (e.g., not just the first "<") and that the result contains br-tags instead of just line-feeds. This is needed as some browsers remove the line feeds when html() is called.
playground/playground.js
--- a/playground/playground.js	Thu Apr 04 16:16:10 2013 -0400
+++ b/playground/playground.js	Fri Apr 05 12:10:11 2013 +0200
@@ -206,8 +206,8 @@
           return callback(err);
         }
         $('#compacted').html(js_beautify(
-          JSON.stringify(compacted).replace('<', '&lt;').replace('>', '&gt;'),
-          {'indent_size': 2}));
+          playground.htmlEscape(JSON.stringify(compacted)),
+          {'indent_size': 2}).replace(/\n/g, '<br>'));
         callback();
       });
     }
@@ -217,8 +217,8 @@
           return callback(err);
         }
         $('#expanded').html(js_beautify(
-          JSON.stringify(expanded).replace('<', '&lt;').replace('>', '&gt;'),
-          {'indent_size': 2}));
+          playground.htmlEscape(JSON.stringify(expanded)),
+          {'indent_size': 2}).replace(/\n/g, '<br>'));
         callback();
       });
     }
@@ -228,8 +228,8 @@
           return callback(err);
         }
         $('#flattened').html(js_beautify(
-          JSON.stringify(flattened).replace('<', '&lt;').replace('>', '&gt;'),
-          {'indent_size': 2}));
+          playground.htmlEscape(JSON.stringify(flattened)),
+          {'indent_size': 2}).replace(/\n/g, '<br>'));
         callback();
       });
     }
@@ -239,8 +239,8 @@
           return callback(err);
         }
         $('#framed').html(js_beautify(
-          JSON.stringify(framed).replace('<', '&lt;').replace('>', '&gt;'),
-          {'indent_size': 2}));
+          playground.htmlEscape(JSON.stringify(framed)),
+          {'indent_size': 2}).replace(/\n/g, '<br>'));
         callback();
       });
     }
@@ -250,7 +250,7 @@
         if(err) {
           return callback(err);
         }
-        $('#nquads').html(playground.htmlEscape(nquads));
+        $('#nquads').html(playground.htmlEscape(nquads).replace(/\n/g, '<br>'));
         callback();
       });
     }
@@ -260,7 +260,7 @@
         if(err) {
           return callback(err);
         }
-        $('#normalized').html(playground.htmlEscape(normalized));
+        $('#normalized').html(playground.htmlEscape(normalized).replace(/\n/g, '<br>'));
         callback();
       });
     }