Files
habitica/website/client/libs/highlightUsers.js
T
negue 92f2079b76 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
2019-02-07 17:55:36 +01:00

19 lines
510 B
JavaScript

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;
}