Skip to content
This repository has been archived by the owner on Oct 27, 2023. It is now read-only.

Commit

Permalink
feat: new mention token
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Jun 23, 2023
1 parent e526b29 commit b742d61
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/components/ui/Markdown/parsers/mention.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
} from '../../Icons/menu-icon'

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

const prefixToUrlMap = {
Expand All @@ -20,10 +20,10 @@ const prefixToUrlMap = {
TG: 'https://t.me/',
}

// {GH@Innei} {TW@Innei} {TG@Innei}
// [...]{GH@Innei} {TW@Innei} {TG@Innei}
export const MentionRule: MarkdownToJSX.Rule = {
match: simpleInlineRegex(
/^\{((?<prefix>(GH)|(TW)|(TG))@(?<name>\w+\b))\}\s?(?!\[.*?\])/,
/^(\[(?<displayName>.*?)\])?\{((?<prefix>(GH)|(TW)|(TG))@(?<name>\w+\b))\}\s?(?!\[.*?\])/,
),
order: Priority.MIN,
parse(capture) {
Expand All @@ -33,7 +33,7 @@ export const MentionRule: MarkdownToJSX.Rule = {
return {}
}
return {
content: { prefix: groups.prefix, name: groups.name },
content: { ...groups },
type: 'mention',
}
},
Expand All @@ -43,28 +43,31 @@ export const MentionRule: MarkdownToJSX.Rule = {
return null as any
}

const { prefix, name } = content
const { prefix, name, displayName } = content
if (!name) {
return null as any
}

// @ts-ignore
const Icon = prefixToIconMap[prefix]
// @ts-ignore
const urlPrefix = prefixToUrlMap[prefix]

return (
<div
className="mr-2 inline-flex items-center space-x-2 align-bottom"
<span
className="mx-1 inline-flex items-center space-x-1 align-bottom"
key={state?.key}
>
{Icon}
<a
target="_blank"
rel="noreferrer nofollow"
href={`${urlPrefix}${name}`}
className="no-underline"
>
{name}
{displayName || name}
</a>
</div>
</span>
)
},
}

1 comment on commit b742d61

@vercel
Copy link

@vercel vercel bot commented on b742d61 Jun 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

kami – ./

kami-git-master-innei-dev.vercel.app
kami-innei-dev.vercel.app
kami-psi.vercel.app
dev.innei.ren

Please sign in to comment.