This commit is contained in:
2023-08-28 15:04:23 +08:00
parent 29209a3a00
commit 84190ed9f1
14 changed files with 1004 additions and 527 deletions

View File

@ -64,4 +64,16 @@ export function escapeHtml(text) {
.replaceAll('\r\n', '<br/>')
.replaceAll('\n', '<br/>')
.replaceAll(' ', '&nbsp;');
}
export function escapeEmoji(text) {
if (text == null) {
return '';
}
if (typeof text !== 'string') {
text = String(text);
}
return text
.replace(/(=[A-Fa-f0-9]{2}){4}/g, s => decodeURIComponent(s.replaceAll('=', '%')))
.replace(/&#x([0-9a-fA-F]{2,6});/g, (_, h) => String.fromCodePoint(parseInt(h, 16)));
}