Skip to content

Commit b742d61

Browse files
committed
feat: new mention token
Signed-off-by: Innei <[email protected]>
1 parent e526b29 commit b742d61

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/components/ui/Markdown/parsers/mention.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import {
99
} from '../../Icons/menu-icon'
1010

1111
const prefixToIconMap = {
12-
GH: <CodiconGithubInverted />,
13-
TW: <MdiTwitter />,
14-
TG: <IcBaselineTelegram />,
12+
GH: <CodiconGithubInverted className="text-[#1D2127] dark:text-[#FFFFFF]" />,
13+
TW: <MdiTwitter className="text-[#1DA1F2]" />,
14+
TG: <IcBaselineTelegram className="text-[#2AABEE]" />,
1515
}
1616

1717
const prefixToUrlMap = {
@@ -20,10 +20,10 @@ const prefixToUrlMap = {
2020
TG: 'https://t.me/',
2121
}
2222

23-
// {GH@Innei} {TW@Innei} {TG@Innei}
23+
// [...]{GH@Innei} {TW@Innei} {TG@Innei}
2424
export const MentionRule: MarkdownToJSX.Rule = {
2525
match: simpleInlineRegex(
26-
/^\{((?<prefix>(GH)|(TW)|(TG))@(?<name>\w+\b))\}\s?(?!\[.*?\])/,
26+
/^(\[(?<displayName>.*?)\])?\{((?<prefix>(GH)|(TW)|(TG))@(?<name>\w+\b))\}\s?(?!\[.*?\])/,
2727
),
2828
order: Priority.MIN,
2929
parse(capture) {
@@ -33,7 +33,7 @@ export const MentionRule: MarkdownToJSX.Rule = {
3333
return {}
3434
}
3535
return {
36-
content: { prefix: groups.prefix, name: groups.name },
36+
content: { ...groups },
3737
type: 'mention',
3838
}
3939
},
@@ -43,28 +43,31 @@ export const MentionRule: MarkdownToJSX.Rule = {
4343
return null as any
4444
}
4545

46-
const { prefix, name } = content
46+
const { prefix, name, displayName } = content
4747
if (!name) {
4848
return null as any
4949
}
5050

51+
// @ts-ignore
5152
const Icon = prefixToIconMap[prefix]
53+
// @ts-ignore
5254
const urlPrefix = prefixToUrlMap[prefix]
5355

5456
return (
55-
<div
56-
className="mr-2 inline-flex items-center space-x-2 align-bottom"
57+
<span
58+
className="mx-1 inline-flex items-center space-x-1 align-bottom"
5759
key={state?.key}
5860
>
5961
{Icon}
6062
<a
6163
target="_blank"
6264
rel="noreferrer nofollow"
6365
href={`${urlPrefix}${name}`}
66+
className="no-underline"
6467
>
65-
{name}
68+
{displayName || name}
6669
</a>
67-
</div>
70+
</span>
6871
)
6972
},
7073
}

0 commit comments

Comments
 (0)