diff --git a/src/components/Reactions.svelte b/src/components/Reactions.svelte
index 95e51f8bd..9ef2ba152 100644
--- a/src/components/Reactions.svelte
+++ b/src/components/Reactions.svelte
@@ -2,7 +2,7 @@
import type { Author } from "@bindings/cob/Author";
import type { Reaction } from "@bindings/cob/Reaction";
- import { twemoji } from "@app/lib/utils";
+ import { emojiToTwemoji } from "@app/lib/utils";
interface Props {
reactions: Reaction[];
@@ -44,12 +44,12 @@
await handleReaction(authors, emoji);
}
}}>
- {emoji}
+ {@html emojiToTwemoji(emoji, ["21a9"])}
{authors.length}
{:else}
- {emoji}
+ {@html emojiToTwemoji(emoji, ["21a9"])}
{authors.length}
{/if}
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index 24bf347d7..10c8616b4 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -102,6 +102,10 @@ export const formatTimestamp = (
return new Date(timestamp).toUTCString();
};
+// Svelte action for replacing emojis within an element with Twemoji SVGs.
+// This action is non-reactive; it only runs when the element is mounted.
+//
+// Usage: 👍
export function twemoji(
node: HTMLElement,
{ exclude }: { exclude: string[] } = { exclude: [] },
@@ -121,6 +125,19 @@ export function twemoji(
});
}
+// Converts a single emoji character to an
tag using Twemoji SVG assets.
+// This function is useful in reactive contexts where Svelte actions won't
+// re-run automatically.
+//
+// Usage: {@html emojiToTwemoji("👍")}
+export function emojiToTwemoji(emoji: string, exclude?: string[]) {
+ const filename = emoji.codePointAt(0)?.toString(16);
+ if (!filename || exclude?.includes(filename)) {
+ return "";
+ }
+ return `
`;
+}
+
export function scrollIntoView(id: string, options?: ScrollIntoViewOptions) {
const lineElement = document.getElementById(id);
if (lineElement) {