Skip to content

Commit

Permalink
fix emoji anchor text with hyperlink
Browse files Browse the repository at this point in the history
  • Loading branch information
dukenv0307 committed May 16, 2023
1 parent 3cdaa94 commit a554878
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -710,3 +710,9 @@ test('Test for link with no content', () => {
const resultString = '[ ](<a href="https://www.link.com" target="_blank" rel="noreferrer noopener">www.link.com</a>)';
expect(parser.replace(testString)).toBe(resultString);
});

test('Test for link with emoji', () => {
const testString = '[😀](www.link.com)';
const resultString = '[😀](<a href="https://www.link.com" target="_blank" rel="noreferrer noopener">www.link.com</a>)';
expect(parser.replace(testString)).toBe(resultString);
});
7 changes: 7 additions & 0 deletions lib/CONST.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,13 @@ export const CONST = {
* @type String
*/
MARKDOWN_EMAIL: "([a-zA-Z0-9.!#$%&'+/=?^`{|}-][a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]*@[a-zA-Z0-9-]+?(\\.[a-zA-Z]+)+)",

/**
* Regex matching an text containing an Emoji
*
* @type RegExp
*/
EMOJIS: /[\p{Extended_Pictographic}\u200d\u{1f1e6}-\u{1f1ff}\u{1f3fb}-\u{1f3ff}\u{e0020}-\u{e007f}\u20E3\uFE0F]|[#*0-9]\uFE0F?\u20E3/gu,
},

REPORT: {
Expand Down
2 changes: 1 addition & 1 deletion lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default class ExpensiMark {
// We use a function here to check if there is already a https:// on the link.
// If there is not, we force the link to be absolute by prepending '//' to the target.
replacement: (match, g1, g2, g3) => {
if (!g1.trim()) {
if (g1.match(CONST.REG_EXP.EMOJIS) || !g1.trim()) {
return match;
}

Expand Down

0 comments on commit a554878

Please sign in to comment.