Add emoji support & render markdown in embeds

This commit is contained in:
TomatoCake 2024-07-13 09:32:34 +02:00
parent 97c264d888
commit 2162b2c1e3
4 changed files with 45 additions and 10 deletions

View file

@ -360,6 +360,42 @@ function markdown(text : string|string[],{keep=false,stdsize=false} = {}){
}
}
if (txt[i] == "<" && txt[i + 1] == ":") {
let found=false;
const build=["<", ":"];
let j=i + 2;
for (; txt[j] !== void 0; j++) {
build.push(txt[j]);
if (txt[j] == ">") {
found=true;
break;
}
}
if (found) {
const parts=build.join("").match(/^<:\w+:(\d{10,30})>$/);
if (parts && parts[1]) {
appendcurrent();
i=j;
const isEmojiOnly = txt.join("").trim()===build.join("").trim();
const emojiElem=document.createElement("img");
emojiElem.classList.add("md-emoji");
emojiElem.width=isEmojiOnly ? 48 : 22;
emojiElem.height=isEmojiOnly ? 48 : 22;
emojiElem.crossOrigin="anonymous";
emojiElem.src=this.info.cdn.toString() + "/emojis/" + parts[1] + ".png?size=32";
emojiElem.alt="";
emojiElem.loading="lazy";
span.appendChild(emojiElem);
continue;
}
}
}
current.textContent+=txt[i];
}
appendcurrent();