' + Tools.escapeHTML(args[1]) + ': (Private to ' + Tools.escapeHTML(args[3]) + ') ' + Tools.parseMessage(args[4]) + '');
break;
case 'askreg':
self.log('
Register an account to protect your ladder rating!
');
diff --git a/js/battledata.js b/js/battledata.js
index 9a3377445..29cabe898 100644
--- a/js/battledata.js
+++ b/js/battledata.js
@@ -101,69 +101,6 @@ function hashColor(name) {
return colorCache[name];
}
-function messageSanitize(str) {
- str = Tools.escapeHTML(str);
- // Don't format console commands (>>).
- if (str.substr(0, 8) === '>>') return str;
- // Don't format console results (<<).
- if (str.substr(0, 8) === '<<') return str;
- return str.
- // ``code``
- replace(/\`\`([^< ]([^<`]*?[^< ])?)\`\`/g, '
$1').
- // ~~strikethrough~~
- replace(/\~\~([^< ]([^<]*?[^< ])?)\~\~/g, '
$1').
- // linking of URIs
- replace(/(https?\:\/\/[a-z0-9-.]+(\/([^\s]*[^\s?.,])?)?|[a-z0-9]([a-z0-9-\.]*[a-z0-9])?\.(com|org|net|edu|us)((\/([^\s]*[^\s?.,])?)?|\b))/ig, function(uri) {
- // Insert http:// before URIs without a URI scheme specified.
- var fulluri = uri.replace(/^([a-z]*[^a-z:])/g, 'http://$1');
- var event;
- if (Tools.interstice.isWhitelisted(fulluri)) {
- event = 'External link';
- } else {
- event = 'Interstice link';
- fulluri = Tools.escapeHTML(Tools.interstice.getURI(Tools.unescapeHTML(fulluri)));
- }
- return '
' + uri + '';
- }).
- // google [blah]
- // google[blah]
- // Google search for 'blah'
- replace(/(\bgoogle ?\[([^\]<]+)\])/ig, function(p0, p1, p2) {
- p2 = Tools.escapeHTML(encodeURIComponent(Tools.unescapeHTML(p2)));
- return '
' + p1 + '';
- }).
- // gl [blah]
- // gl[blah
- // Google search for 'blah' and visit the first result ("I'm feeling lucky")
- replace(/(\bgl ?\[([^\]<]+)\])/ig, function(p0, p1, p2) {
- p2 = Tools.escapeHTML(encodeURIComponent(Tools.unescapeHTML(p2)));
- return '
' + p1 + '';
- }).
- // wiki [blah]
- // Search Wikipedia for 'blah' (and visit the article for 'blah' if it exists)
- replace(/(\bwiki ?\[([^\]<]+)\])/ig, function(p0, p1, p2) {
- p2 = Tools.escapeHTML(encodeURIComponent(Tools.unescapeHTML(p2)));
- return '
' + p1 + '';
- }).
- // [[blah]]
- // Short form of gl[[blah]]
- replace(/\[\[([^< ]([^<`]*?[^< ])?)\]\]/ig, function(p0, p1) {
- var q = Tools.escapeHTML(encodeURIComponent(Tools.unescapeHTML(p1)));
- return '
' + p1 +'';
- }).
- // __italics__
- replace(/\_\_([^< ]([^<]*?[^< ])?)\_\_/g, '
$1').
- // **bold**
- replace(/\*\*([^< ]([^<]*?[^< ])?)\*\*/g, '
$1');
-}
-
function toId(text) {
text = text || '';
if (typeof text === 'number') text = ''+text;
@@ -360,6 +297,69 @@ var Tools = {
return Tools.escapeHTML(formatid);
},
+ parseMessage: function(str) {
+ str = Tools.escapeHTML(str);
+ // Don't format console commands (>>).
+ if (str.substr(0, 8) === '>>') return str;
+ // Don't format console results (<<).
+ if (str.substr(0, 8) === '<<') return str;
+ return str.
+ // ``code``
+ replace(/\`\`([^< ]([^<`]*?[^< ])?)\`\`/g, '
$1').
+ // ~~strikethrough~~
+ replace(/\~\~([^< ]([^<]*?[^< ])?)\~\~/g, '
$1').
+ // linking of URIs
+ replace(/(https?\:\/\/[a-z0-9-.]+(\/([^\s]*[^\s?.,])?)?|[a-z0-9]([a-z0-9-\.]*[a-z0-9])?\.(com|org|net|edu|us)((\/([^\s]*[^\s?.,])?)?|\b))/ig, function(uri) {
+ // Insert http:// before URIs without a URI scheme specified.
+ var fulluri = uri.replace(/^([a-z]*[^a-z:])/g, 'http://$1');
+ var event;
+ if (Tools.interstice.isWhitelisted(fulluri)) {
+ event = 'External link';
+ } else {
+ event = 'Interstice link';
+ fulluri = Tools.escapeHTML(Tools.interstice.getURI(Tools.unescapeHTML(fulluri)));
+ }
+ return '
' + uri + '';
+ }).
+ // google [blah]
+ // google[blah]
+ // Google search for 'blah'
+ replace(/(\bgoogle ?\[([^\]<]+)\])/ig, function(p0, p1, p2) {
+ p2 = Tools.escapeHTML(encodeURIComponent(Tools.unescapeHTML(p2)));
+ return '
' + p1 + '';
+ }).
+ // gl [blah]
+ // gl[blah
+ // Google search for 'blah' and visit the first result ("I'm feeling lucky")
+ replace(/(\bgl ?\[([^\]<]+)\])/ig, function(p0, p1, p2) {
+ p2 = Tools.escapeHTML(encodeURIComponent(Tools.unescapeHTML(p2)));
+ return '
' + p1 + '';
+ }).
+ // wiki [blah]
+ // Search Wikipedia for 'blah' (and visit the article for 'blah' if it exists)
+ replace(/(\bwiki ?\[([^\]<]+)\])/ig, function(p0, p1, p2) {
+ p2 = Tools.escapeHTML(encodeURIComponent(Tools.unescapeHTML(p2)));
+ return '
' + p1 + '';
+ }).
+ // [[blah]]
+ // Short form of gl[[blah]]
+ replace(/\[\[([^< ]([^<`]*?[^< ])?)\]\]/ig, function(p0, p1) {
+ var q = Tools.escapeHTML(encodeURIComponent(Tools.unescapeHTML(p1)));
+ return '
' + p1 +'';
+ }).
+ // __italics__
+ replace(/\_\_([^< ]([^<]*?[^< ])?)\_\_/g, '
$1').
+ // **bold**
+ replace(/\*\*([^< ]([^<]*?[^< ])?)\*\*/g, '
$1');
+ },
+
escapeHTML: function(str, jsEscapeToo) {
str = (str?''+str:'');
str = str.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"');
diff --git a/js/client-chat.js b/js/client-chat.js
index 48368171b..3c6413de0 100644
--- a/js/client-chat.js
+++ b/js/client-chat.js
@@ -733,13 +733,13 @@
var pmuserid = toUserid(pm);
var oName = pm;
if (pmuserid === app.user.get('userid')) oName = name;
- this.$chat.append('
' + timestamp + '' + clickableName + ': (Private to ' + Tools.escapeHTML(pm) + ') ' + messageSanitize(message) + '
');
+ this.$chat.append('
' + timestamp + '' + clickableName + ': (Private to ' + Tools.escapeHTML(pm) + ') ' + Tools.parseMessage(message) + '
');
} else if (message.substr(0,4).toLowerCase() === '/me ') {
- this.$chat.append(chatDiv + timestamp + '
• ' + clickableName + ' ' + messageSanitize(message.substr(4)) + '