From 793209ae57aea71ab96bed5e2b64e7938a20ec50 Mon Sep 17 00:00:00 2001 From: Matheus Clemente Date: Mon, 15 Jan 2024 17:47:16 -0300 Subject: [PATCH] Allow HTML elements in chat messages Related to #345. --- src/module/hooks.js | 7 ++++--- src/module/logic.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/module/hooks.js b/src/module/hooks.js index 66887bf..1f4116b 100644 --- a/src/module/hooks.js +++ b/src/module/hooks.js @@ -127,11 +127,12 @@ export default class PolyglotHooks { !game.polyglot._isTruespeech(lang) && !known && (game.user.character || isGM ? !understood : true); } const forceTranslation = message.polyglot_force || !message.polyglot_unknown; + const innerText = html.find(".message-content")[0].innerText; const content = $("
") .addClass("polyglot-original-text") .css({ font: game.polyglot._getFontStyle(lang) }) - .html(game.polyglot.scrambleString(message.content, message.id, lang)); + .html(game.polyglot.scrambleString(innerText, message.id, lang)); const translation = $("
") .addClass("polyglot-translation-text") .attr("data-tooltip", language) @@ -142,7 +143,7 @@ export default class PolyglotHooks { displayTranslated && (lang !== game.polyglot.languageProvider.defaultLanguage || message.polyglot_unknown) ) { - html.find(".message-content").empty().append(content); + html.find(".message-content")[0].innerText = content; if ( forceTranslation || (!game.polyglot._isTruespeech(lang) && !message.polyglot_unknown && (isGM || !hideTranslation)) @@ -150,7 +151,7 @@ export default class PolyglotHooks { html.find(".message-content").append(translation); } } else if (!forceTranslation && message.polyglot_unknown) { - html.find(".message-content").empty().append(content); + html.find(".message-content")[0].innerText = content; } if (isGM || ((known || understood) && !hideTranslation)) { diff --git a/src/module/logic.js b/src/module/logic.js index b05f6cd..f5fe0d2 100644 --- a/src/module/logic.js +++ b/src/module/logic.js @@ -546,7 +546,7 @@ export class Polyglot { * @returns {Boolean} - Whether the message content is a link to an image file or not. */ _isMessageLink(messageContent) { - return /@|<|https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)$/gi.test( + return /@|https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)$/gi.test( messageContent, ); }