xonecas.io
5414
Sa

sat / files

sat / src / components / markdown-content.tsx

2.1 KB
1import { memo } from "react";
2import ReactMarkdown, { type Components } from "react-markdown";
3
4const components: Components = {
5  h1: ({ children }) => (
6    <h1 className="scroll-m-20 text-2xl font-extrabold tracking-tight lg:text-3xl">
7      {children}
8    </h1>
9  ),
10  h2: ({ children }) => (
11    <h2 className="scroll-m-20 border-b pb-2 text-xl font-semibold tracking-tight first:mt-0">
12      {children}
13    </h2>
14  ),
15  h3: ({ children }) => (
16    <h3 className="scroll-m-20 text-lg font-semibold tracking-tight">
17      {children}
18    </h3>
19  ),
20  h4: ({ children }) => (
21    <h4 className="scroll-m-20 text-base font-semibold tracking-tight">
22      {children}
23    </h4>
24  ),
25  p: ({ children }) => <p className="leading-7 not-first:mt-4">{children}</p>,
26  blockquote: ({ children }) => (
27    <blockquote className="mt-4 border-l-2 pl-6 italic">{children}</blockquote>
28  ),
29  ul: ({ children }) => (
30    <ul className="my-4 ml-6 list-disc [&>li]:mt-2">{children}</ul>
31  ),
32  ol: ({ children }) => (
33    <ol className="my-4 ml-6 list-decimal [&>li]:mt-2">{children}</ol>
34  ),
35  code: ({ children }) => (
36    <code className="bg-muted relative rounded px-[0.3rem] py-[0.2rem] font-mono text-sm">
37      {children}
38    </code>
39  ),
40  pre: ({ children }) => (
41    <pre className="bg-muted mt-4 overflow-x-auto rounded-lg p-4 font-mono text-sm">
42      {children}
43    </pre>
44  ),
45  a: ({ href, children }) => (
46    <a
47      href={href}
48      target="_blank"
49      rel="noopener noreferrer"
50      className="text-primary underline underline-offset-4 hover:no-underline"
51    >
52      {children}
53    </a>
54  ),
55  table: ({ children }) => (
56    <div className="my-4 w-full overflow-y-auto">
57      <table className="w-full">{children}</table>
58    </div>
59  ),
60  th: ({ children }) => (
61    <th className="border px-4 py-2 text-left font-bold">{children}</th>
62  ),
63  td: ({ children }) => <td className="border px-4 py-2">{children}</td>,
64  hr: () => <hr className="my-8 border-t" />,
65};
66
67export const MarkdownContent = memo(function MarkdownContent({
68  content,
69}: {
70  content: string;
71}) {
72  return <ReactMarkdown components={components}>{content}</ReactMarkdown>;
73});