mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-26 21:24:08 +00:00
19 lines
510 B
JavaScript
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;
|
||
|
|
}
|