Skip to content

Commit

Permalink
feat: support legacy gemoji (#873)
Browse files Browse the repository at this point in the history
| [![PR App][icn]][demo] | Fix RM-9702 |
| :--------------------: | :---------: |

## 🧰 Changes

Adds support for our legacy emoji syntax.

Previously, we swapped out our custom emoji library for a more standard one. Unrealized by me, our custom one used dashes instead of underscores. This checks if the same emoji name exists using underscores instead of dashes.
  • Loading branch information
kellyjosephprice committed May 7, 2024
1 parent f4ae2e1 commit c34b8fe
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
7 changes: 7 additions & 0 deletions __tests__/flavored-compilers/gemoji.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '_'));
});
});
26 changes: 26 additions & 0 deletions __tests__/gemoji-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,32 @@ test('should output an <i> 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}:.`;
Expand Down
14 changes: 13 additions & 1 deletion processor/parse/gemoji-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit c34b8fe

Please sign in to comment.