From bef1b2b74ee3a9311d7e3bd01b8ea9cadbc3995d Mon Sep 17 00:00:00 2001 From: Shusui MOYATANI Date: Fri, 19 May 2023 20:42:34 +0900 Subject: [PATCH] feat: support underscore in emoji --- src/nostr/parseTextNote.test.ts | 6 +++++- src/nostr/parseTextNote.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/nostr/parseTextNote.test.ts b/src/nostr/parseTextNote.test.ts index 7b57d49..74f031c 100644 --- a/src/nostr/parseTextNote.test.ts +++ b/src/nostr/parseTextNote.test.ts @@ -192,6 +192,10 @@ describe('parseTextNote', () => { given: ':bunhd:', expected: [{ type: 'CustomEmoji', content: ':bunhd:', shortcode: 'bunhd' }], }, + { + given: ':sushi_maguro:', + expected: [{ type: 'CustomEmoji', content: ':sushi_maguro:', shortcode: 'sushi_maguro' }], + }, { given: 'Good morning! :pv:!', expected: [ @@ -212,7 +216,7 @@ describe('parseTextNote', () => { assert.deepStrictEqual(parsed, expected); }); - it.each([':bunhd_hop:', ':hello', '::: NOSTR :::'])( + it.each([':bunhd-hop:', ':+1:', ':-1:', ':hello', '::: NOSTR :::'])( 'should parse text note which includes invalid custom emoji ($emoji)', (content) => { const parsed = parseTextNote(content); diff --git a/src/nostr/parseTextNote.ts b/src/nostr/parseTextNote.ts index 331e884..0409d03 100644 --- a/src/nostr/parseTextNote.ts +++ b/src/nostr/parseTextNote.ts @@ -79,7 +79,7 @@ const tagRefRegex = /(?:#\[(?\d+)\])/g; const mentionRegex = /(?(?nostr:)?(?(?:npub|note|nprofile|nevent)1[ac-hj-np-z02-9]+))/gi; const hashTagRegex = /#(?[\p{Letter}\p{Number}_]+)/gu; -const customEmojiRegex = /:(?[a-zA-Z0-9]+):/gu; +const customEmojiRegex = /:(?\w+):/gu; const parseTextNote = (textNoteContent: string) => { const matches = [