From 947d41d9d25582e39e9ed85f637621189f304b95 Mon Sep 17 00:00:00 2001 From: lily Date: Mon, 9 Sep 2024 14:59:12 +0100 Subject: [PATCH] improve emoji code parsing --- src/internal/parser.ts | 5 ++--- test/api.ts | 1 - test/parser.ts | 6 ++++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/internal/parser.ts b/src/internal/parser.ts index 3795706..f59b3ed 100644 --- a/src/internal/parser.ts +++ b/src/internal/parser.ts @@ -645,14 +645,13 @@ export const language = P.createLanguage({ }, emojiCode: () => { - const side = P.notMatch(P.regexp(/[a-z0-9]/i)); const mark = P.str(':'); return P.seq( - P.alt([P.lineBegin, side]), + P.notRegexpBefore(/[a-z0-9]$/i), mark, P.regexp(/[a-z0-9_+-]+/i), mark, - P.alt([P.lineEnd, side]), + P.alt([P.lineEnd, P.notMatch(P.regexp(/[a-z0-9]/i))]), ).select(2).map(name => M.EMOJI_CODE(name)); }, diff --git a/test/api.ts b/test/api.ts index 25b29e2..c3a3c6f 100644 --- a/test/api.ts +++ b/test/api.ts @@ -204,7 +204,6 @@ after`; test('nested', () => { const nodes = mfm.parse('abc:hoge:$[tada 123 @hoge :foo:]:piyo:'); const expect = [ - EMOJI_CODE('hoge'), EMOJI_CODE('foo'), EMOJI_CODE('piyo') ]; diff --git a/test/parser.ts b/test/parser.ts index 852699c..2b6a942 100644 --- a/test/parser.ts +++ b/test/parser.ts @@ -49,6 +49,12 @@ describe('SimpleParser', () => { const output = [TEXT('あ'), EMOJI_CODE('bar'), TEXT('い')]; assert.deepStrictEqual(mfm.parseSimple(input), output); }); + + test('end of text', () => { + const input = 'At 10:30:'; + const output = [TEXT('At 10:30:')]; + assert.deepStrictEqual(mfm.parseSimple(input), output); + }); }); test('disallow other syntaxes', () => {