feat: transform code for display

This commit is contained in:
shadcn
2026-01-06 16:58:56 +04:00
parent eb098f87d2
commit 413dc4c01f
2 changed files with 176 additions and 80 deletions

View File

@@ -4,6 +4,7 @@ import * as React from "react"
import { highlightCode } from "@/lib/highlight-code"
import { getRegistryItem } from "@/lib/registry"
import { transformForDisplay } from "@/lib/rehype"
import { cn } from "@/lib/utils"
import { CodeCollapsibleWrapper } from "@/components/code-collapsible-wrapper"
import { CopyButton } from "@/components/copy-button"
@@ -53,6 +54,9 @@ export async function ComponentSource({
code = code.replaceAll("export default", "export")
code = code.replaceAll("/* eslint-disable react/no-children-prop */\n", "")
// Apply transforms (cn-* → Tailwind, IconPlaceholder → icons, etc.).
code = await transformForDisplay(code, styleName)
const lang = language ?? title?.split(".").pop() ?? "tsx"
const highlightedCode = await highlightCode(code, lang)