Skip to content

Commit

Permalink
improve emoji code parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
lily committed Sep 9, 2024
1 parent c237368 commit b726e97
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/internal/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,14 +645,13 @@ export const language = P.createLanguage<TypeTable>({
},

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));
},

Expand Down
1 change: 0 additions & 1 deletion test/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
];
Expand Down
6 changes: 6 additions & 0 deletions test/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit b726e97

Please sign in to comment.