-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mention style and strike through style
- Loading branch information
1 parent
e0ee2f5
commit 02ce215
Showing
2 changed files
with
38 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import ReactMarkdown from "react-markdown"; | ||
import rehypeRaw from "rehype-raw"; | ||
|
||
const MarkdownPreview = ({ markdown }: { markdown: string }) => { | ||
const processedMarkdown = markdown | ||
.replace( | ||
/!\[mention_user\]\(user_id:(\d+), username:([^)]+)\)/g, | ||
(_, userId, username) => | ||
`<a class="rounded bg-blue-100 px-1 font-normal text-slate-800 no-underline hover:underline" data-user-id="${userId}" data-username="${username}">@${username}</a>`, | ||
) | ||
.replace(/~(.*?)~/g, (_, text) => `<del>${text}</del>`); | ||
|
||
return ( | ||
<ReactMarkdown className="prose" rehypePlugins={[rehypeRaw]}> | ||
{processedMarkdown} | ||
</ReactMarkdown> | ||
); | ||
}; | ||
|
||
export default MarkdownPreview; |