diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js
index 9d316307..dc9e200b 100644
--- a/__tests__/ExpensiMark-HTML-test.js
+++ b/__tests__/ExpensiMark-HTML-test.js
@@ -866,18 +866,6 @@ test('Test for user mention with text with inlineCodeBlock style', () => {
expect(parser.replace(testString)).toBe(resultString);
});
-test('Test for user mention inside link markdown', () => {
- const testString = '[@username@expensify.com](expensify.com)';
- const resultString = '@username@expensify.com';
- expect(parser.replace(testString)).toBe(resultString);
-});
-
-test('Test for user mention inside email markdown', () => {
- const testString = '[@username@expensify.com](username@expensify.com)';
- const resultString = '@username@expensify.com';
- expect(parser.replace(testString)).toBe(resultString);
-});
-
test('Test for user mention without space or supported styling character', () => {
const testString = 'hi@username@expensify.com';
const resultString = 'hi@username@expensify.com';
@@ -985,6 +973,52 @@ test('Test for @here mention without space or supported styling character', () =
expect(parser.replace(testString)).toBe(resultString);
});
+test('Test for mention inside link and email markdown', () => {
+ const testString = '[@username@expensify.com](expensify.com) '
+ + '[_@username@expensify.com_](expensify.com) '
+ + '[*@username@expensify.com*](expensify.com) '
+ + '[~@username@expensify.com~](expensify.com) '
+ + '[`@username@expensify.com`](expensify.com) '
+ + '[@here](expensify.com) '
+ + '[_@here_](expensify.com) '
+ + '[*@here*](expensify.com) '
+ + '[~@here~](expensify.com) '
+ + '[`@here`](expensify.com) '
+ + '[@username@expensify.com](username@expensify.com) '
+ + '[_@username@expensify.com_](username@expensify.com) '
+ + '[*@username@expensify.com*](username@expensify.com) '
+ + '[~@username@expensify.com~](username@expensify.com) '
+ + '[`@username@expensify.com`](username@expensify.com) '
+ + '[@here](username@expensify.com) '
+ + '[_@here_](username@expensify.com) '
+ + '[*@here*](username@expensify.com) '
+ + '[~@here~](username@expensify.com) '
+ + '[`@here`](username@expensify.com)';
+
+ const resultString = '@username@expensify.com '
+ + '@username@expensify.com '
+ + '@username@expensify.com '
+ + '@username@expensify.com '
+ + '@username@expensify.com
'
+ + '@here '
+ + '@here '
+ + '@here '
+ + '@here '
+ + '@here
'
+ + '@username@expensify.com '
+ + '@username@expensify.com '
+ + '@username@expensify.com '
+ + '@username@expensify.com '
+ + '@username@expensify.com
'
+ + '@here '
+ + '@here '
+ + '@here '
+ + '@here '
+ + '@here
';
+
+ expect(parser.replace(testString)).toBe(resultString);
+});
+
test('Skip rendering invalid markdown',() => {
let testString = '_*test_*';
expect(parser.replace(testString)).toBe('*test*');
diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js
index 321156ca..08d3b976 100644
--- a/lib/ExpensiMark.js
+++ b/lib/ExpensiMark.js
@@ -92,7 +92,7 @@ export default class ExpensiMark {
*/
{
name: 'hereMentions',
- regex: /[`.a-zA-Z]?@here(?=_\b|\b)(?![^<]*(<\/pre>|<\/code>|<\/a>))/gm,
+ regex: /[`.a-zA-Z]?@here(?=_\b|\b)(?!((?:(?!|[^<]*(<\/pre>|<\/code>))/gm,
replacement: (match) => {
if (!Str.isValidMention(match)) {
return match;
@@ -110,7 +110,7 @@ export default class ExpensiMark {
*/
{
name: 'userMentions',
- regex: new RegExp(`[\`.a-zA-Z]?@+${CONST.REG_EXP.EMAIL_PART}(?![^<]*(<\\/pre>|<\\/code>|<\\/a>))`, 'gm'),
+ regex: new RegExp(`[\`.a-zA-Z]?@+${CONST.REG_EXP.EMAIL_PART}(?!((?:(?!|[^<]*(<\\/pre>|<\\/code>))`, 'gm'),
replacement: (match) => {
if (!Str.isValidMention(match)) {
return match;