Support text formatting in |error| (#1652)

This commit is contained in:
Mia
2020-11-02 10:50:14 -06:00
committed by GitHub
parent acf8feb611
commit 2d215a2c4e
3 changed files with 5 additions and 5 deletions

View File

@@ -1448,7 +1448,7 @@
break;
case 'error':
this.$chat.append('<div class="notice message-error">' + BattleLog.escapeHTML(row.slice(1).join('|')) + '</div>');
this.$chat.append('<div class="notice message-error">' + BattleLog.parseMessage(row.slice(1).join('|'), true) + '</div>');
break;
case 'uhtml':

View File

@@ -614,7 +614,7 @@ class BattleLog {
case 'text':
return ['chat', BattleLog.parseMessage(target)];
case 'error':
return ['chat message-error', BattleLog.escapeHTML(target)];
return ['chat message-error', formatText(target, true)];
case 'html':
return [
'chat chatmessage-' + toID(name) + hlClass + mineClass,
@@ -645,12 +645,12 @@ class BattleLog {
}
}
static parseMessage(str: string) {
static parseMessage(str: string, isTrusted = false) {
// Don't format console commands (>>).
if (str.substr(0, 3) === '>> ' || str.substr(0, 4) === '>>> ') return this.escapeHTML(str);
// Don't format console results (<<).
if (str.substr(0, 3) === '<< ') return this.escapeHTML(str);
str = formatText(str);
str = formatText(str, isTrusted);
let options = BattleLog.prefs('chatformatting') || {};

2
src/globals.d.ts vendored
View File

@@ -29,7 +29,7 @@ declare var BattlePokemonSpritesBW: any;
// defined in battle-log-misc
declare function MD5(input: string): string;
declare function formatText(input: string): string;
declare function formatText(input: string, isTrusted?: boolean): string;
// PS globals
/////////////