From 57d233dc043c5d90d16a8708d8bbdb8a82037cf8 Mon Sep 17 00:00:00 2001 From: Taesu Date: Fri, 19 Dec 2025 12:22:30 +0900 Subject: [PATCH] split Pre component --- docs/components/markdown.tsx | 37 ++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/docs/components/markdown.tsx b/docs/components/markdown.tsx index 3b255e941e..75b9da1781 100644 --- a/docs/components/markdown.tsx +++ b/docs/components/markdown.tsx @@ -111,23 +111,26 @@ function reindent(code: string): string { return result.join("\n"); } -function Pre(props: ComponentProps<"pre">) { - const code = Children.only(props.children) as ReactElement; - const codeProps = code.props as ComponentProps<"code">; - const content = codeProps.children; - if (typeof content !== "string") return null; - - let lang = - codeProps.className +function CodeBlock({ + content, + className, +}: { + content: string; + className?: string; +}) { + const lang = + className ?.split(" ") .find((v) => v.startsWith("language-")) ?.slice("language-".length) ?? "text"; - if (lang === "mdx") lang = "md"; + const displayLang = lang === "mdx" ? "md" : lang; const formattedCode = useMemo(() => { if ( - ["ts", "tsx", "typescript", "js", "javascript", "json"].includes(lang) + ["ts", "tsx", "typescript", "js", "javascript", "json"].includes( + displayLang, + ) ) { return js_beautify(content, { indent_size: 2, @@ -136,15 +139,25 @@ function Pre(props: ComponentProps<"pre">) { }).trim(); } return reindent(content.trimEnd()); - }, [content, lang]); + }, [content, displayLang]); return (
- +
); } +function Pre(props: ComponentProps<"pre">) { + const code = Children.only(props.children) as ReactElement; + const codeProps = code.props as ComponentProps<"code">; + const content = codeProps.children; + + if (typeof content !== "string") return null; + + return ; +} + const processor = createProcessor(); export function Markdown({ text }: { text: string }) {