normalise emoji text

also, tests
This commit is contained in:
dakkar 2024-03-09 09:39:48 +00:00
parent 7b6749fc35
commit f5359d4656
2 changed files with 25 additions and 1 deletions

View file

@ -629,7 +629,7 @@ export const language = P.createLanguage({
P.regexp(/[\p{Letter}\p{Number}\p{Mark}_+-]+/iu), P.regexp(/[\p{Letter}\p{Number}\p{Mark}_+-]+/iu),
mark, mark,
P.alt([P.lineEnd, side]), P.alt([P.lineEnd, side]),
], 2).map(name => M.EMOJI_CODE(name as string)); ], 2).map(name => M.EMOJI_CODE((name as string).normalize('NFC')));
}, },
link: r => { link: r => {

View file

@ -338,6 +338,30 @@ hoge`;
const output = [EMOJI_CODE('abc')]; const output = [EMOJI_CODE('abc')];
assert.deepStrictEqual(mfm.parse(input), output); assert.deepStrictEqual(mfm.parse(input), output);
}); });
test('non-ASCII', () => {
const input = ':taneŝima_ĝojas:, :मार्जारः:, :鹅:, :taneŝima_malsanas:, :แมว:, and :लक्षणा:';
const output = [
EMOJI_CODE('taneŝima_ĝojas'),
TEXT(', '),
EMOJI_CODE('मार्जारः'),
TEXT(', '),
EMOJI_CODE('鹅'),
TEXT(', '),
EMOJI_CODE('taneŝima_malsanas'),
TEXT(', '),
EMOJI_CODE('แมว'),
TEXT(', and '),
EMOJI_CODE('लक्षणा'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
test('non-ASCII normalization', () => {
const input = ":fo\u{0308}o:";
const output = [EMOJI_CODE("f\u{00F6}o")];
assert.deepStrictEqual(mfm.parse(input), output);
});
}); });
describe('unicode emoji', () => { describe('unicode emoji', () => {