Mention highlighting to only highlight w/username mentions

This commit is contained in:
Hafiz
2025-08-10 21:02:48 -05:00
parent 78df6cd657
commit ae4ecc72ef
2 changed files with 15 additions and 1 deletions
@@ -152,6 +152,11 @@
<style lang="scss">
.message-card {
.at-highlight {
background-color: rgba(213, 200, 255, 0.32);
padding: 0.1rem;
}
.at-text {
color: #6133b4;
}
+10 -1
View File
@@ -3,5 +3,14 @@ import habiticaMarkdown from 'habitica-markdown/withMentions';
export default function renderWithMentions (text, user) {
if (!text) return null;
const env = { userName: user.auth.local.username, displayName: user.profile.name };
return habiticaMarkdown.render(String(text), env);
let html = habiticaMarkdown.render(String(text), env);
if (user.profile.name && user.profile.name !== user.auth.local.username) {
const escapedDisplayName = user.profile.name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const displayNameRegex = new RegExp(
`(<span class="at-text) at-highlight(">@${escapedDisplayName}</span>)`,
'gi',
);
html = html.replace(displayNameRegex, '$1$2');
}
return html;
}