diff --git a/website/client/src/libs/highlightUsers.js b/website/client/src/libs/highlightUsers.js
index 89b3b4d3c8..7cd42c37b2 100644
--- a/website/client/src/libs/highlightUsers.js
+++ b/website/client/src/libs/highlightUsers.js
@@ -1,7 +1,7 @@
import escapeRegExp from 'lodash/escapeRegExp';
const optionalAnchorTagRegExStr = '(<\\w[^>]*)?'; // everything including the anchor tag is recognized
-const mentionRegExStr = '(@[\\w-]+)';
+const mentionRegExStr = '(@(?:<(?:em|strong)>)?[\\w-]+(?:<\\/(?:em|strong)>)?)';
const optionalPostMentionRegExStr = '(\\.\\w+)?'; // like dot-TLD
const finalMentionRegEx = new RegExp(`${optionalAnchorTagRegExStr}${mentionRegExStr}${optionalPostMentionRegExStr}`, 'gi');
@@ -14,9 +14,12 @@ export function highlightUsers (text, userName, displayName) { // eslint-disable
return fullMatched;
}
- const isUserMention = currentUser.includes(mentionStr) ? 'at-highlight' : '';
+ let fixedStr = mentionStr.replace(/<\/?em>/g, '_');
+ fixedStr = fixedStr.replace(/<\/?strong>/g, '__');
- return fullMatched.replace(mentionStr, `${mentionStr}`);
+ const isUserMention = currentUser.includes(fixedStr) ? 'at-highlight' : '';
+
+ return fullMatched.replace(mentionStr, `${fixedStr}`);
});
return text;
diff --git a/website/client/tests/unit/libs/highlightUsers.spec.js b/website/client/tests/unit/libs/highlightUsers.spec.js
index 1a36d1f1fa..9f3ba6b865 100644
--- a/website/client/tests/unit/libs/highlightUsers.spec.js
+++ b/website/client/tests/unit/libs/highlightUsers.spec.js
@@ -17,6 +17,24 @@ describe('highlightUserAndEmail', () => {
expect(result).to.contain('@user');
});
+ it('highlights username sandwiched with underscores', () => {
+ const text = 'hello @user';
+
+ const result = highlightUsers(text, '_user_', 'displayedUser');
+ expect(result).to.contain('@_user_');
+ expect(result).to.not.contain('');
+ expect(result).to.not.contain('');
+ });
+
+ it('highlights username sandwiched with double underscores', () => {
+ const text = 'hello @user';
+
+ const result = highlightUsers(text, 'diffUser', 'displayDiffUser');
+ expect(result).to.contain('@__user__');
+ expect(result).to.not.contain('');
+ expect(result).to.not.contain('');
+ });
+
it('not highlights any email', () => {
const text = habiticaMarkdown.render('hello@example.com');