Skip to content

Commit

Permalink
Allow HTML elements in chat messages
Browse files Browse the repository at this point in the history
Related to #345.
  • Loading branch information
mclemente committed Jan 15, 2024
1 parent 67b878a commit 793209a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/module/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $("<div>")
.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 = $("<div>")
.addClass("polyglot-translation-text")
.attr("data-tooltip", language)
Expand All @@ -142,15 +143,15 @@ 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))
) {
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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/module/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
Expand Down

0 comments on commit 793209a

Please sign in to comment.