Permalink
Browse files

Clean up to HTML representation, and only do it if the character is p…

…resent.
  • Loading branch information...
1 parent 7a07101 commit e4ddf0b57235bf1dc53bf6672c11b648a3977b01 @tgvashworth tgvashworth committed Oct 17, 2012
Showing with 12 additions and 7 deletions.
  1. +12 −7 lib/utils.js
View
@@ -209,15 +209,20 @@ module.exports = {
return params.join(',');
},
cleanForRender: function (str) {
- // Stolen & twiddled from @mathias
- // https://github.com/mathiasbynens/mothereff.in/blob/master/js-escapes/eff.js
var cache = {
- '\u2028': '\\u2028',
- '\u2029': '\\u2029'
+ '\u2028': '
',
+ '\u2029': '
'
};
- return str.replace(/[\s\S]/g, function(character) {
- return cache[character] || character;
- });
+ var re, bad;
+
+ for (bad in cache) {
+ if (str.indexOf(bad) != -1) {
+ re = new RegExp(bad, 'g');
+ str = str.replace(re, cache[bad]);
+ }
+ }
+
+ return str;
}
};

0 comments on commit e4ddf0b

Please sign in to comment.