feat: support underscore in emoji

This commit is contained in:
Shusui MOYATANI
2023-05-19 20:42:34 +09:00
parent ee6731023e
commit bef1b2b74e
2 changed files with 6 additions and 2 deletions

View File

@@ -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);

View File

@@ -79,7 +79,7 @@ const tagRefRegex = /(?:#\[(?<idx>\d+)\])/g;
const mentionRegex =
/(?<mention>(?<nip19>nostr:)?(?<bech32>(?:npub|note|nprofile|nevent)1[ac-hj-np-z02-9]+))/gi;
const hashTagRegex = /#(?<hashtag>[\p{Letter}\p{Number}_]+)/gu;
const customEmojiRegex = /:(?<emoji>[a-zA-Z0-9]+):/gu;
const customEmojiRegex = /:(?<emoji>\w+):/gu;
const parseTextNote = (textNoteContent: string) => {
const matches = [