Skip to content

Commit

Permalink
Now handling HTML entities when formatting messages with emotes (Frit…
Browse files Browse the repository at this point in the history
…zAndFriends#255)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
csharpfritz and github-actions[bot] committed Oct 20, 2023
1 parent 758e397 commit d1b887e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/TagzApp.Web/wwwroot/js/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
observer.observe(taggedContent, observerConfig);
}

function decodeHtml(html) {
var txt = document.createElement('textarea');
txt.innerHTML = html;
return txt.value;
}

async function start() {
try {
await connection.start();
Expand Down Expand Up @@ -317,7 +323,7 @@
}

function FormatContextWithEmotes(content) {
var text = content.text;
var text = decodeHtml(content.text);
if (!content.emotes) return text;

var toReplace = [];
Expand All @@ -330,11 +336,15 @@
.substring(emote.pos, emote.length + emote.pos + 1)
.trim();
var emoteHtml = `<img class="emote" src="${emoteUrl}" />`;
console.log(
`Formatting text: '${text}' with emote at ${emote.pos}, with length ${emote.length} and found text ${emoteName}`,
);
toReplace.push({ name: emoteName, html: emoteHtml });
}

for (var r in toReplace) {
var item = toReplace[r];
console.log(`Replacing ${item.name} with ${item.html}`);
text = text.replace(item.name, item.html);
}

Expand Down

0 comments on commit d1b887e

Please sign in to comment.