Skip to content

Commit

Permalink
Fix: mfm - do not parse emoji before include char
Browse files Browse the repository at this point in the history
  • Loading branch information
fs5m8 committed Jan 12, 2023
1 parent cd6f2cc commit 3027922
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/mfm/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,13 @@ export const mfmLanguage = P.createLanguage({
});
},
emoji: () => {
const name = P.regexp(/:([a-z0-9_+-]+):/i, 1).map(x => createLeaf('emoji', { name: x }));
const name = P((input, i) => {
const text = input.substring(i);
const match = text.match(/^(\*|:)([a-zA-Z0-9_+-]+?)\1/);
if (!match) return P.makeFailure(i, 'not a emoji');
if (input[i - 1] != null && input[i - 1].match(/[a-zA-Z0-9_+-]/i)) return P.makeFailure(i, 'not a emoji');
return P.makeSuccess(i + match[0].length, match[2]);
}).map(x => createLeaf('emoji', { name: x }));
const code = P.regexp(emojiRegex).map(x => createLeaf('emoji', { emoji: x }));
return P.alt(name, code);
},
Expand Down

0 comments on commit 3027922

Please sign in to comment.