2025-04-04 05:00:36 +00:00
|
|
|
import "@/styles/mdx.css";
|
2025-05-07 05:31:02 +00:00
|
|
|
import {
|
|
|
|
DefaultDarkThemeConfig,
|
|
|
|
DefaultLightThemeConfig,
|
|
|
|
} from "@/config/monaco-theme";
|
2025-03-07 03:37:24 +00:00
|
|
|
import { cn } from "@/lib/utils";
|
|
|
|
import "katex/dist/katex.min.css";
|
|
|
|
import remarkGfm from "remark-gfm";
|
|
|
|
import remarkMath from "remark-math";
|
|
|
|
import rehypeKatex from "rehype-katex";
|
|
|
|
import { MDXRemote } from "next-mdx-remote/rsc";
|
|
|
|
import rehypePrettyCode from "rehype-pretty-code";
|
|
|
|
import { MdxComponents } from "@/components/content/mdx-components";
|
|
|
|
|
|
|
|
interface MdxRendererProps {
|
|
|
|
source: string;
|
|
|
|
className?: string;
|
|
|
|
}
|
|
|
|
|
2025-05-07 05:31:02 +00:00
|
|
|
const MdxRenderer = ({ source, className }: MdxRendererProps) => {
|
2025-03-07 03:37:24 +00:00
|
|
|
return (
|
2025-05-07 05:31:02 +00:00
|
|
|
<article className={cn("markdown-body", className)}>
|
|
|
|
<MDXRemote
|
|
|
|
source={source}
|
|
|
|
options={{
|
|
|
|
mdxOptions: {
|
|
|
|
rehypePlugins: [
|
|
|
|
rehypeKatex,
|
|
|
|
[
|
|
|
|
rehypePrettyCode,
|
|
|
|
{
|
|
|
|
theme: {
|
|
|
|
light: DefaultLightThemeConfig.id,
|
|
|
|
dark: DefaultDarkThemeConfig.id,
|
2025-03-07 03:37:24 +00:00
|
|
|
},
|
2025-05-07 05:31:02 +00:00
|
|
|
keepBackground: false,
|
|
|
|
},
|
2025-03-07 03:37:24 +00:00
|
|
|
],
|
2025-05-07 05:31:02 +00:00
|
|
|
],
|
|
|
|
remarkPlugins: [remarkGfm, remarkMath],
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
components={MdxComponents}
|
|
|
|
/>
|
|
|
|
</article>
|
2025-03-07 03:37:24 +00:00
|
|
|
);
|
2025-05-07 05:31:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export { MdxRenderer };
|