mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
fix emails in chat (#10912)
* additional regex checks to ignore the <tag attribute="content"> * extract highlightUsers method - add test * refactor highlight regex * refactor the regex without `lookbehind` * remove unneeded regex
This commit is contained in:
18
website/client/libs/highlightUsers.js
Normal file
18
website/client/libs/highlightUsers.js
Normal file
@@ -0,0 +1,18 @@
|
||||
export function highlightUsers (text, userName, displayName) {
|
||||
const findAnyMentionRegex = '@[\\w-]+(?:\\b)';
|
||||
|
||||
const atRegex = new RegExp(`${findAnyMentionRegex}`, 'gi');
|
||||
const currentUser = [`@${userName}`, `@${displayName}`];
|
||||
|
||||
if (atRegex.test(text)) {
|
||||
text = text.replace(atRegex, match => {
|
||||
if (currentUser.includes(match)) {
|
||||
return `<span class="at-highlight at-text">${match}</span>`;
|
||||
}
|
||||
|
||||
return `<span class="at-text">${match}</span>`;
|
||||
});
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
Reference in New Issue
Block a user