Fix #1536 - add support for emoji variants in tags

This commit is contained in:
Riccardo Ferretti
2025-11-07 15:41:54 +01:00
parent 3d49146087
commit cbebdaf427
2 changed files with 24 additions and 2 deletions

View File

@@ -1,8 +1,8 @@
import { isSome } from './core';
export const HASHTAG_REGEX =
/(?<=^|\s)#([0-9]*[\p{L}\p{Emoji_Presentation}/_-][\p{L}\p{Emoji_Presentation}\p{N}/_-]*)/gmu;
/(?<=^|\s)#([0-9]*[\p{L}\p{Extended_Pictographic}/_-](?:[\p{L}\p{Extended_Pictographic}\p{N}/_-]|\uFE0F|\p{Emoji_Modifier})*)/gmu;
export const WORD_REGEX =
/(?<=^|\s)([0-9]*[\p{L}\p{Emoji_Presentation}/_-][\p{L}\p{Emoji_Presentation}\p{N}/_-]*)/gmu;
/(?<=^|\s)([0-9]*[\p{L}\p{Extended_Pictographic}/_-](?:[\p{L}\p{Extended_Pictographic}\p{N}/_-]|\uFE0F|\p{Emoji_Modifier})*)/gmu;
export const extractHashtags = (
text: string

View File

@@ -80,6 +80,28 @@ describe('hashtag extraction', () => {
]);
});
it('supports emoji tags with variant selectors (issue #1536)', () => {
expect(
extractHashtags('#🗃️/37-Education #🔖/37/Learning #🟣HOUSE #🟠MONEY').map(
t => t.label
)
).toEqual(['🗃️/37-Education', '🔖/37/Learning', '🟣HOUSE', '🟠MONEY']);
});
it('supports individual emojis with variant selectors', () => {
// Test each emoji separately to debug
expect(extractHashtags('#🗃️').map(t => t.label)).toEqual(['🗃️']);
expect(extractHashtags('#🔖').map(t => t.label)).toEqual(['🔖']);
});
it('supports emojis that work without variant selector', () => {
// These emojis should work with current implementation
expect(extractHashtags('#📥 #⭐').map(t => t.label)).toEqual([
'📥',
'⭐',
]);
});
it('ignores hashes in plain text urls and links', () => {
expect(
extractHashtags(`