fix: Improve mentions behavior

This commit is contained in:
Maksim Eltyshev
2025-08-11 13:52:17 +02:00
parent cbb00d1d59
commit 6515877eb6
9 changed files with 89 additions and 30 deletions

View File

@@ -4,19 +4,17 @@
*/
const MENTION_ID_REGEX = /@\[.*?\]\((.*?)\)/g;
const MENTION_NAME_REGEX = /@\[(.*?)\]\(.*?\)/g;
const MENTION_USERNAME_REGEX = /@\[(.*?)\]\(.*?\)/g;
const extractMentionIds = (text) => {
const matches = [...text.matchAll(MENTION_ID_REGEX)];
return matches.map((match) => match[1]);
};
const formatTextWithMentions = (text) => text.replace(MENTION_NAME_REGEX, '@$1');
const mentionMarkupToText = (markup) =>
markup.replace(MENTION_USERNAME_REGEX, (_, username) => `@${username}`);
module.exports = {
MENTION_ID_REGEX,
MENTION_NAME_REGEX,
extractMentionIds,
formatTextWithMentions,
mentionMarkupToText,
};