Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

refactor: improve mentions

robinf4ff604a91c2
diff --git a/ui/src/components/Mentions/index.tsx b/ui/src/components/Mentions/index.tsx
index cc63e85a..9b29c86d 100644
--- a/ui/src/components/Mentions/index.tsx
+++ b/ui/src/components/Mentions/index.tsx
@@ -73,7 +73,7 @@ const Mentions: FC<IProps> = ({ children, pageUsers, onSelected }) => {
return;
}
- const text = `@${item?.displayName}[${item?.userName}] `;
+ const text = `@${item?.userName}`;
onSelected(
`${value.substring(
0,
diff --git a/ui/src/utils/index.ts b/ui/src/utils/index.ts
index 0e23dfe2..2912ca0c 100644
--- a/ui/src/utils/index.ts
+++ b/ui/src/utils/index.ts
@@ -78,8 +78,8 @@ function scrollTop(element) {
* @returns Array<{displayName: string, userName: string}>
*/
function matchedUsers(markdown) {
- const globalReg = /@(.*?)\[(.*?)\]/gm;
- const reg = /@(.*?)\[(.*?)\]/;
+ const globalReg = /\B@([\w\\_\\.]+)/g;
+ const reg = /\B@([\w\\_\\.]+)/;
const users = markdown.match(globalReg);
if (!users) {
@@ -88,8 +88,7 @@ function matchedUsers(markdown) {
return users.map((user) => {
const matched = user.match(reg);
return {
- displayName: matched[2],
- userName: matched[2],
+ userName: matched[1],
};
});
}
@@ -100,8 +99,8 @@ function matchedUsers(markdown) {
* @returns string
*/
function parseUserInfo(markdown) {
- const globalReg = /@(.*?)\[(.*?)\]/gm;
- return markdown.replace(globalReg, '[@$1](/u/$2)');
+ const globalReg = /\B@([\w\\_\\.]+)/g;
+ return markdown.replace(globalReg, '[@$1](/u/$1)');
}
export {