Fix emoji rendering for dashed emoji codes (#48)

* Fix custom emoji shortcode matching to include dashes

The regex pattern for matching NIP-30 custom emoji shortcodes was missing
the dash character, causing emojis like :work-out: to fail matching.
Updated both ReactionRenderer and ReactionCompactPreview to use
[a-zA-Z0-9_-] instead of [a-zA-Z0-9_].

* Refactor: extract emoji shortcode regex to constant

Move the emoji shortcode matching pattern to EMOJI_SHORTCODE_REGEX
constant in emoji-helpers.ts for reuse across reaction renderers.

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Alejandro
2026-01-09 11:03:43 +01:00
committed by GitHub
parent a1fe411161
commit 84b5ac88aa
3 changed files with 10 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ import { Heart, ThumbsUp, ThumbsDown, Flame, Smile } from "lucide-react";
import { useNostrEvent } from "@/hooks/useNostrEvent";
import { UserName } from "../UserName";
import { RichText } from "../RichText";
import { EMOJI_SHORTCODE_REGEX } from "@/lib/emoji-helpers";
/**
* Compact preview for Kind 7 (Reaction)
@@ -26,7 +27,7 @@ export function ReactionCompactPreview({ event }: { event: NostrEvent }) {
// Parse reaction content for custom emoji
const parsedReaction = useMemo(() => {
const match = reaction.match(/^:([a-zA-Z0-9_]+):$/);
const match = reaction.match(EMOJI_SHORTCODE_REGEX);
if (match && customEmojis[match[1]]) {
return {
type: "custom" as const,

View File

@@ -6,6 +6,7 @@ import { NostrEvent } from "@/types/nostr";
import { KindRenderer } from "./index";
import { EventCardSkeleton } from "@/components/ui/skeleton";
import { parseReplaceableAddress } from "applesauce-core/helpers/pointers";
import { EMOJI_SHORTCODE_REGEX } from "@/lib/emoji-helpers";
/**
* Renderer for Kind 7 - Reactions
@@ -32,7 +33,7 @@ export function Kind7Renderer({ event }: BaseEventProps) {
// Parse reaction content to detect custom emoji shortcodes
// Format: :shortcode: in the content
const parsedReaction = useMemo(() => {
const match = reaction.match(/^:([a-zA-Z0-9_]+):$/);
const match = reaction.match(EMOJI_SHORTCODE_REGEX);
if (match && customEmojis[match[1]]) {
return {
type: "custom" as const,

View File

@@ -1,6 +1,12 @@
import { getOrComputeCachedValue } from "applesauce-core/helpers";
import type { NostrEvent } from "@/types/nostr";
/**
* Regex pattern to match NIP-30 custom emoji shortcodes like :shortcode:
* Supports alphanumeric characters, underscores, and dashes
*/
export const EMOJI_SHORTCODE_REGEX = /^:([a-zA-Z0-9_-]+):$/;
/**
* Represents a parsed emoji tag from NIP-30
*/