diff --git a/__tests__/flavored-compilers/gemoji.test.js b/__tests__/flavored-compilers/gemoji.test.js index 16be2915a..c7e2978ca 100644 --- a/__tests__/flavored-compilers/gemoji.test.js +++ b/__tests__/flavored-compilers/gemoji.test.js @@ -7,4 +7,11 @@ describe('gemoji compiler', () => { expect(md(tree)).toMatch(doc); }); + + it('writes legacy gemojis back to shortcodes', () => { + const doc = ':white-check-mark:'; + const tree = mdast(doc); + + expect(md(tree)).toMatch(doc.replaceAll(/-/g, '_')); + }); }); diff --git a/__tests__/gemoji-parser.test.js b/__tests__/gemoji-parser.test.js index c8847cd17..a249feabe 100644 --- a/__tests__/gemoji-parser.test.js +++ b/__tests__/gemoji-parser.test.js @@ -94,6 +94,32 @@ test('should output an for a font awesome icon', () => { ); }); +test('should support legacy dashes', () => { + const emoji = 'white-check-mark'; + const markdown = `This is a gemoji :${emoji}:.`; + const ast = { + type: 'root', + children: [ + { + type: 'paragraph', + children: [ + { type: 'text', value: 'This is a gemoji ' }, + { + type: 'gemoji', + value: '✅', + name: 'white_check_mark', + }, + { type: 'text', value: '.' }, + ], + }, + ], + }; + + expect(unified().use(remarkParse).use(parser).data('settings', { position: false }).parse(markdown)).toStrictEqual( + ast, + ); +}); + test('should output nothing for unknown emojis', () => { const emoji = 'unknown-emoji'; const markdown = `This is a gemoji :${emoji}:.`; diff --git a/processor/parse/gemoji-parser.js b/processor/parse/gemoji-parser.js index f43b26efc..db1b6af66 100644 --- a/processor/parse/gemoji-parser.js +++ b/processor/parse/gemoji-parser.js @@ -50,8 +50,20 @@ function tokenize(eat, value, silent) { }, }, }); - default: + default: { + if (name.match(/-/)) { + const standardized = name.replaceAll(/-/g, '_'); + if (Owlmoji.kind(standardized) === 'gemoji') { + return eat(match)({ + type: 'gemoji', + value: Owlmoji.nameToEmoji[standardized], + name: standardized, + }); + } + } + return false; + } } }