mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-18 15:26:33 +00:00
feat(components): add MdxRenderer for rendering MDX content with custom styling and syntax highlighting
This commit is contained in:
parent
9eb6f89587
commit
f1b6e86123
54
src/components/content/mdx-renderer.tsx
Normal file
54
src/components/content/mdx-renderer.tsx
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import "@/style/mdx.css";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { Suspense } from "react";
|
||||||
|
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 { Skeleton } from "@/components/ui/skeleton";
|
||||||
|
import { MdxComponents } from "@/components/content/mdx-components";
|
||||||
|
import { DefaultDarkThemeConfig, DefaultLightThemeConfig } from "@/config/monaco-theme";
|
||||||
|
|
||||||
|
interface MdxRendererProps {
|
||||||
|
source: string;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function MdxRenderer({ source, className }: MdxRendererProps) {
|
||||||
|
return (
|
||||||
|
<Suspense
|
||||||
|
fallback={
|
||||||
|
<div className="h-full w-full p-4">
|
||||||
|
<Skeleton className="h-full w-full rounded-3xl" />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<article className={cn("markdown-body", className)}>
|
||||||
|
<MDXRemote
|
||||||
|
source={source}
|
||||||
|
options={{
|
||||||
|
mdxOptions: {
|
||||||
|
rehypePlugins: [
|
||||||
|
rehypeKatex,
|
||||||
|
[
|
||||||
|
rehypePrettyCode,
|
||||||
|
{
|
||||||
|
theme: {
|
||||||
|
light: DefaultLightThemeConfig.id,
|
||||||
|
dark: DefaultDarkThemeConfig.id,
|
||||||
|
},
|
||||||
|
keepBackground: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
|
remarkPlugins: [remarkGfm, remarkMath],
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
components={MdxComponents}
|
||||||
|
/>
|
||||||
|
</article>
|
||||||
|
</Suspense>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user