mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-17 23:12:23 +00:00
refactor(mdx-renderer): simplify component implementation
- Remove Suspense and Skeleton loading state - Convert to arrow function syntax - Reorganize import statements - Simplify export syntax
This commit is contained in:
parent
2c7223a323
commit
2e19c08e8b
@ -1,54 +1,49 @@
|
|||||||
import "@/styles/mdx.css";
|
import "@/styles/mdx.css";
|
||||||
|
import {
|
||||||
|
DefaultDarkThemeConfig,
|
||||||
|
DefaultLightThemeConfig,
|
||||||
|
} from "@/config/monaco-theme";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { Suspense } from "react";
|
|
||||||
import "katex/dist/katex.min.css";
|
import "katex/dist/katex.min.css";
|
||||||
import remarkGfm from "remark-gfm";
|
import remarkGfm from "remark-gfm";
|
||||||
import remarkMath from "remark-math";
|
import remarkMath from "remark-math";
|
||||||
import rehypeKatex from "rehype-katex";
|
import rehypeKatex from "rehype-katex";
|
||||||
import { MDXRemote } from "next-mdx-remote/rsc";
|
import { MDXRemote } from "next-mdx-remote/rsc";
|
||||||
import rehypePrettyCode from "rehype-pretty-code";
|
import rehypePrettyCode from "rehype-pretty-code";
|
||||||
import { Skeleton } from "@/components/ui/skeleton";
|
|
||||||
import { MdxComponents } from "@/components/content/mdx-components";
|
import { MdxComponents } from "@/components/content/mdx-components";
|
||||||
import { DefaultDarkThemeConfig, DefaultLightThemeConfig } from "@/config/monaco-theme";
|
|
||||||
|
|
||||||
interface MdxRendererProps {
|
interface MdxRendererProps {
|
||||||
source: string;
|
source: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function MdxRenderer({ source, className }: MdxRendererProps) {
|
const MdxRenderer = ({ source, className }: MdxRendererProps) => {
|
||||||
return (
|
return (
|
||||||
<Suspense
|
<article className={cn("markdown-body", className)}>
|
||||||
fallback={
|
<MDXRemote
|
||||||
<div className="h-full w-full p-4">
|
source={source}
|
||||||
<Skeleton className="h-full w-full rounded-3xl" />
|
options={{
|
||||||
</div>
|
mdxOptions: {
|
||||||
}
|
rehypePlugins: [
|
||||||
>
|
rehypeKatex,
|
||||||
<article className={cn("markdown-body", className)}>
|
[
|
||||||
<MDXRemote
|
rehypePrettyCode,
|
||||||
source={source}
|
{
|
||||||
options={{
|
theme: {
|
||||||
mdxOptions: {
|
light: DefaultLightThemeConfig.id,
|
||||||
rehypePlugins: [
|
dark: DefaultDarkThemeConfig.id,
|
||||||
rehypeKatex,
|
|
||||||
[
|
|
||||||
rehypePrettyCode,
|
|
||||||
{
|
|
||||||
theme: {
|
|
||||||
light: DefaultLightThemeConfig.id,
|
|
||||||
dark: DefaultDarkThemeConfig.id,
|
|
||||||
},
|
|
||||||
keepBackground: false,
|
|
||||||
},
|
},
|
||||||
],
|
keepBackground: false,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
remarkPlugins: [remarkGfm, remarkMath],
|
],
|
||||||
},
|
remarkPlugins: [remarkGfm, remarkMath],
|
||||||
}}
|
},
|
||||||
components={MdxComponents}
|
}}
|
||||||
/>
|
components={MdxComponents}
|
||||||
</article>
|
/>
|
||||||
</Suspense>
|
</article>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export { MdxRenderer };
|
||||||
|
Loading…
Reference in New Issue
Block a user