2024-02-01 13:40:44 +05:30
|
|
|
import remarkGfm from "remark-gfm"
|
|
|
|
|
import remarkMath from "remark-math"
|
2024-06-03 15:55:12 +05:30
|
|
|
import ReactMarkdown from "react-markdown"
|
2024-02-01 23:48:40 +05:30
|
|
|
import "property-information"
|
2024-02-01 13:40:44 +05:30
|
|
|
import React from "react"
|
2024-05-30 23:49:18 +05:30
|
|
|
import { CodeBlock } from "./CodeBlock"
|
|
|
|
|
|
|
|
|
|
|
2024-02-01 13:40:44 +05:30
|
|
|
export default function Markdown({ message }: { message: string }) {
|
2024-05-30 23:49:18 +05:30
|
|
|
|
2024-02-01 13:40:44 +05:30
|
|
|
return (
|
|
|
|
|
<React.Fragment>
|
2024-06-03 15:55:12 +05:30
|
|
|
<ReactMarkdown
|
2024-02-25 00:12:46 +05:30
|
|
|
className="prose break-words dark:prose-invert prose-p:leading-relaxed prose-pre:p-0 dark:prose-dark"
|
2024-02-17 00:01:07 +05:30
|
|
|
remarkPlugins={[remarkGfm, remarkMath]}
|
2024-02-01 13:40:44 +05:30
|
|
|
components={{
|
|
|
|
|
code({ node, inline, className, children, ...props }) {
|
|
|
|
|
const match = /language-(\w+)/.exec(className || "")
|
|
|
|
|
return !inline ? (
|
2024-05-30 23:49:18 +05:30
|
|
|
<CodeBlock
|
|
|
|
|
language={match ? match[1] : ""}
|
|
|
|
|
value={String(children).replace(/\n$/, "")}
|
|
|
|
|
/>
|
2024-02-01 13:40:44 +05:30
|
|
|
) : (
|
|
|
|
|
<code className={`${className} font-semibold`} {...props}>
|
|
|
|
|
{children}
|
|
|
|
|
</code>
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
a({ node, ...props }) {
|
|
|
|
|
return (
|
|
|
|
|
<a
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noreferrer"
|
|
|
|
|
className="text-blue-500 text-sm hover:underline"
|
|
|
|
|
{...props}>
|
|
|
|
|
{props.children}
|
|
|
|
|
</a>
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
p({ children }) {
|
|
|
|
|
return <p className="mb-2 last:mb-0">{children}</p>
|
|
|
|
|
}
|
|
|
|
|
}}>
|
|
|
|
|
{message}
|
2024-06-03 15:55:12 +05:30
|
|
|
</ReactMarkdown>
|
2024-02-01 13:40:44 +05:30
|
|
|
</React.Fragment>
|
|
|
|
|
)
|
|
|
|
|
}
|