aboutsummaryrefslogtreecommitdiff
path: root/src/lib/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/utils.ts')
-rw-r--r--src/lib/utils.ts12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index 5d8ecc8..f93f68e 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -120,4 +120,16 @@ export function shuffle<T>(a: T[]): T[] {
;[a[i], a[j]] = [a[j], a[i]]
}
return a
+}
+
+const emojiRegex = /(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g
+
+
+export function twemojiHtml(s: string) {
+ const htmlEncoded = s.replace('<', '&lt;').replace('>', '&gt;').replace('&', '&amp;')
+ // replace unicode emojis with <img src="/emoji/[hex].svg">
+ const asTwemoji = htmlEncoded.replace(emojiRegex, (match) => {
+ return `<img src="/emoji/${[...match].map(p => p.codePointAt(0).toString(16)).join('-')}.svg" class="emoji">`
+ })
+ return asTwemoji
} \ No newline at end of file