Skip to content

Production-ready animations, transitions, backgrounds, and scenes for Remotion

feat: redesign code block

dev_wandryb5e02c8cc4f4
diff --git a/app/globals.css b/app/globals.css
index 93be0209..1af7bb13 100644
--- a/app/globals.css
+++ b/app/globals.css
@@ -43,6 +43,10 @@
--color-popover: var(--popover);
--color-card-foreground: var(--card-foreground);
--color-card: var(--card);
+ --color-code: var(--code);
+ --color-code-foreground: var(--code-foreground);
+ --color-code-highlight: var(--code-highlight);
+ --color-code-number: var(--code-number);
--radius-sm: calc(var(--radius) * 0.6);
--radius-md: calc(var(--radius) * 0.8);
--radius-lg: var(--radius);
@@ -94,6 +98,10 @@
--sidebar-accent-foreground: oklch(0.205 0 0);
--sidebar-border: oklch(0.922 0 0);
--sidebar-ring: oklch(0.708 0 0);
+ --code: oklch(0.97 0 0);
+ --code-foreground: oklch(0.145 0 0);
+ --code-highlight: oklch(0.93 0 0);
+ --code-number: oklch(0.556 0 0);
/* "NEW" sidebar badge — editable accent. Theme-agnostic for now (same value
in light/dark); recolor the badge by changing --badge-new-bg here. The fg
@@ -135,6 +143,10 @@
--sidebar-accent-foreground: oklch(0.95 0 0);
--sidebar-border: oklch(1 0 0 / 6%);
--sidebar-ring: oklch(1 0 0 / 20%);
+ --code: oklch(0.16 0.008 290);
+ --code-foreground: oklch(0.95 0 0);
+ --code-highlight: oklch(0.24 0.008 290);
+ --code-number: oklch(0.55 0.008 290);
/* Badge keeps the same lime accent in dark mode — see :root for the knob. */
--badge-new-bg: rgb(195, 232, 141);
@@ -227,6 +239,96 @@
background-color: transparent !important;
}
+[data-rehype-pretty-code-figure] {
+ position: relative;
+ overflow: hidden;
+ border-radius: var(--radius-xl);
+ background-color: var(--color-code);
+ color: var(--color-code-foreground);
+ font-size: var(--text-sm);
+ line-height: 1.7;
+ outline: none;
+}
+[data-rehype-pretty-code-figure]:has([data-rehype-pretty-code-title])
+ [data-slot="copy-button"] {
+ top: calc(var(--spacing) * 1.5);
+}
+[data-rehype-pretty-code-figure] pre,
+[data-rehype-pretty-code-figure] code {
+ font-family: var(--font-mono);
+}
+[data-rehype-pretty-code-figure] code,
+[data-rehype-pretty-code-figure] code span {
+ font-variant-ligatures: none;
+ font-feature-settings:
+ "liga" 0,
+ "calt" 0;
+}
+
+[data-rehype-pretty-code-title] {
+ border-bottom: 1px solid var(--border);
+ padding-block: calc(var(--spacing) * 2.5);
+ padding-inline: calc(var(--spacing) * 4);
+ font-family: var(--font-mono);
+ font-size: var(--text-sm);
+ color: var(--color-code-foreground);
+}
+
+[data-line-numbers] {
+ display: grid;
+ min-width: 100%;
+ white-space: pre;
+ counter-reset: line;
+ box-decoration-break: clone;
+}
+[data-line-numbers] [data-line]::before {
+ counter-increment: line;
+ content: counter(line);
+ display: inline-block;
+ width: calc(var(--spacing) * 16);
+ padding-right: calc(var(--spacing) * 6);
+ text-align: right;
+ color: var(--color-code-number);
+ background-color: var(--color-code);
+ position: sticky;
+ left: 0;
+}
+[data-line-numbers] [data-highlighted-line][data-line]::before {
+ background-color: var(--color-code-highlight);
+}
+
+[data-line] {
+ display: inline-block;
+ width: 100%;
+ padding-block: calc(var(--spacing) * 0.25);
+}
+[data-line] span {
+ color: var(--shiki-light);
+}
+.dark [data-line] span {
+ /* biome-ignore lint/complexity/noImportantStyles: shiki inlines the light color in the style attribute; only !important can flip it to the dark palette */
+ color: var(--shiki-dark) !important;
+}
+
+[data-highlighted-line],
+[data-highlighted-chars] {
+ position: relative;
+ background-color: var(--color-code-highlight);
+}
+[data-highlighted-line]::after {
+ content: "";
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 2px;
+ height: 100%;
+ background-color: color-mix(
+ in oklab,
+ var(--muted-foreground) 50%,
+ transparent
+ );
+}
+
#nd-sidebar a,
#nd-sidebar-mobile a {
font-size: 0.8125rem;
diff --git a/bun.lock b/bun.lock
index a4d4a337..afd17d6d 100644
--- a/bun.lock
+++ b/bun.lock
@@ -34,6 +34,7 @@
"react": "19.2.4",
"react-dom": "19.2.4",
"react-resizable-panels": "^4.9.0",
+ "rehype-pretty-code": "^0.14.4",
"remotion": "4.0.473",
"server-only": "^0.0.1",
"sonner": "^2.0.7",
@@ -941,6 +942,8 @@
"hasown": ["[email protected]", "", { "dependencies": { "function-bind": "^1.1.2" } }, "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ=="],
+ "hast-util-from-html": ["[email protected]", "", { "dependencies": { "@types/hast": "^3.0.0", "devlop": "^1.1.0", "hast-util-from-parse5": "^8.0.0", "parse5": "^7.0.0", "vfile": "^6.0.0", "vfile-message": "^4.0.0" } }, "sha512-CUSRHXyKjzHov8yKsQjGOElXy/3EKpyX56ELnkHH34vDVw1N1XSQ1ZcAvTyAPtGqLTuKP/uxM+aLkSPqF/EtMw=="],
+
"hast-util-from-parse5": ["[email protected]", "", { "dependencies": { "@types/hast": "^3.0.0", "@types/unist": "^3.0.0", "devlop": "^1.0.0", "hastscript": "^9.0.0", "property-information": "^7.0.0", "vfile": "^6.0.0", "vfile-location": "^5.0.0", "web-namespaces": "^2.0.0" } }, "sha512-3kxEVkEKt0zvcZ3hCRYI8rqrgwtlIOFMWkbclACvjlDw8Li9S2hk/d51OI0nr/gIpdMHNepwgOKqZ/sy0Clpyg=="],
"hast-util-parse-selector": ["[email protected]", "", { "dependencies": { "@types/hast": "^3.0.0" } }, "sha512-wkQCkSYoOGCRKERFWcxMVMOcYE2K1AaNLU8DXS9arxnLOUEWbOXKXiJUNzEpqZ3JOKpnha3jkFrumEjVliDe7A=="],
@@ -1293,6 +1296,8 @@
"parse-ms": ["[email protected]", "", {}, "sha512-TXfryirbmq34y8QBwgqCVLi+8oA3oWx2eAnSn62ITyEhEYaWRlVZ2DvMM9eZbMs/RfxPu/PK/aBLyGj4IrqMHw=="],
+ "parse-numeric-range": ["[email protected]", "", {}, "sha512-twN+njEipszzlMJd4ONUYgSfZPDxgHhT9Ahed5uTigpQn90FggW4SA/AIPq/6a149fTbE9qBEcSwE3FAEp6wQQ=="],
+
"parse5": ["[email protected]", "", { "dependencies": { "entities": "^6.0.0" } }, "sha512-IInvU7fabl34qmi9gY8XOVxhYyMyuH2xUNpb2q8/Y+7552KlejkRvqvD19nMoUW/uQGGbqNpA6Tufu5FL5BZgw=="],
"parseurl": ["[email protected]", "", {}, "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ=="],
@@ -1377,6 +1382,10 @@
"regex-utilities": ["[email protected]", "", {}, "sha512-8VhliFJAWRaUiVvREIiW2NXXTmHs4vMNnSzuJVhscgmGav3g9VDxLrQndI3dZZVVdp0ZO/5v0xmX516/7M9cng=="],
+ "rehype-parse": ["[email protected]", "", { "dependencies": { "@types/hast": "^3.0.0", "hast-util-from-html": "^2.0.0", "unified": "^11.0.0" } }, "sha512-ksCzCD0Fgfh7trPDxr2rSylbwq9iYDkSn8TCDmEJ49ljEUBxDVCzCHv7QNzZOfODanX4+bWQ4WZqLCRWYLfhag=="],
+
+ "rehype-pretty-code": ["[email protected]", "", { "dependencies": { "@types/hast": "^3.0.4", "hast-util-to-string": "^3.0.0", "parse-numeric-range": "^1.3.0", "rehype-parse": "^9.0.0", "unified": "^11.0.5", "unist-util-visit": "^5.0.0" }, "peerDependencies": { "shiki": "^1.0.0 || ^2.0.0 || ^3.0.0 || ^4.0.0" } }, "sha512-FKPkiSnTqtJHKjCwfqfQs0tXSkmcq7K3jsryZI0rpazo2kWgSYw+sk18GAhxDzKdPk004WWWZ5yiZFEUQhN4Bg=="],
+
"rehype-raw": ["[email protected]", "", { "dependencies": { "@types/hast": "^3.0.0", "hast-util-raw": "^9.0.0", "vfile": "^6.0.0" } }, "sha512-/aE8hCfKlQeA8LmyeyQvQF3eBiLRGNlfBJEvWH7ivp9sBqs7TNqBL5X3v157rM4IFETqDnIOO+z5M/biZbo9Ww=="],
"rehype-recma": ["[email protected]", "", { "dependencies": { "@types/estree": "^1.0.0", "@types/hast": "^3.0.0", "hast-util-to-estree": "^3.0.0" } }, "sha512-lqA4rGUf1JmacCNWWZx0Wv1dHqMwxzsDWYMTowuplHF3xH0N/MmrZ/G3BDZnzAkRmxDadujCjaKM2hqYdCBOGw=="],
diff --git a/components/docs/block-preview.tsx b/components/docs/block-preview.tsx
index 538a9e51..cd35382e 100644
--- a/components/docs/block-preview.tsx
+++ b/components/docs/block-preview.tsx
@@ -1,13 +1,13 @@
"use client";
-import { DynamicCodeBlock } from "fumadocs-ui/components/dynamic-codeblock";
+import { CodeBlock } from "@/components/docs/code-block";
import { PreviewStage } from "@/lib/ui-preview-internals";
import { blockExamples } from "./examples/blocks";
/**
* Controls-free preview for composition blocks. A THIN wrapper over
* `PreviewStage` (`lib/ui-preview-internals.tsx` — owns lazy-mount + autoplay)
- * plus `DynamicCodeBlock`: the live scene Player above, the copyable scene
+ * plus the shared `CodeBlock`: the live scene Player above, the copyable scene
* snippet below. No Tabs, no customizer, no nuqs, no controls.
*
* Replaces both the vestigial `LiveExample` and `UiComponentPreview` for the
@@ -47,9 +47,7 @@ export function BlockPreview({ name }: { name: string }) {
previewBackdrop={entry.previewBackdrop}
/>
- <div className="surface-card overflow-hidden rounded-2xl [&_pre]:!rounded-none [&_pre]:!border-0 [&_pre]:!bg-transparent">
- <DynamicCodeBlock lang="tsx" code={code} />
- </div>
+ <CodeBlock code={code} />
</div>
);
}
diff --git a/components/docs/code-block.tsx b/components/docs/code-block.tsx
new file mode 100644
index 00000000..1d283fa0
--- /dev/null
+++ b/components/docs/code-block.tsx
@@ -0,0 +1,65 @@
+"use client";
+
+import { DynamicCodeBlock } from "fumadocs-ui/components/dynamic-codeblock";
+import type { ComponentProps } from "react";
+import type { ShikiTransformer } from "shiki";
+import { CopyButton } from "@/components/docs/copy-button";
+import { cn } from "@/lib/utils";
+
+const transformers: ShikiTransformer[] = [
+ {
+ pre(node) {
+ node.properties.style = undefined;
+ },
+ code(node) {
+ if (this.source.split("\n").length > 1) {
+ node.properties["data-line-numbers"] = "";
+ }
+ },
+ line(node) {
+ node.properties["data-line"] = "";
+ },
+ },
+];
+
+function Pre({ className, ...props }: ComponentProps<"pre">) {
+ return (
+ <pre
+ className={cn(
+ "no-scrollbar min-w-0 overflow-x-auto px-4 py-3.5 outline-none has-data-line-numbers:px-0",
+ className,
+ )}
+ {...props}
+ />
+ );
+}
+
+export function CodeBlock({
+ code,
+ lang = "tsx",
+ className,
+}: {
+ code: string;
+ lang?: string;
+ className?: string;
+}) {
+ return (
+ <div data-rehype-pretty-code-figure="" className={className}>
+ <CopyButton value={code} className="absolute top-3 right-2 z-10" />
+ <DynamicCodeBlock
+ lang={lang}
+ code={code}
+ options={{
+ themes: {
+ light: "github-light-default",
+ dark: "vesper",
+ },
+ transformers,
+ components: {
+ pre: Pre,
+ },
+ }}
+ />
+ </div>
+ );
+}
diff --git a/components/docs/code-icons.tsx b/components/docs/code-icons.tsx
new file mode 100644
index 00000000..199e6e62
--- /dev/null
+++ b/components/docs/code-icons.tsx
@@ -0,0 +1,45 @@
+import { FileIcon } from "lucide-react";
+import type { ComponentProps } from "react";
+
+function TypeScriptIcon(props: ComponentProps<"svg">) {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 24 24"
+ fill="currentColor"
+ {...props}
+ >
+ <path d="M1.125 0C.502 0 0 .502 0 1.125v21.75C0 23.498.502 24 1.125 24h21.75c.623 0 1.125-.502 1.125-1.125V1.125C24 .502 23.498 0 22.875 0zm17.363 9.75c.612 0 1.154.037 1.627.111a6.38 6.38 0 0 1 1.306.34v2.458a3.95 3.95 0 0 0-.643-.361 5.093 5.093 0 0 0-.717-.26 5.453 5.453 0 0 0-1.426-.2c-.3 0-.573.028-.819.086a2.1 2.1 0 0 0-.623.242c-.17.104-.3.229-.393.374a.888.888 0 0 0-.14.49c0 .196.053.373.156.529.104.156.252.304.443.444s.423.276.696.41c.273.135.582.274.926.416.47.197.892.407 1.266.628.374.222.695.473.963.753.268.279.472.598.614.957.142.359.214.776.214 1.253 0 .657-.125 1.21-.373 1.656a3.033 3.033 0 0 1-1.012 1.085 4.38 4.38 0 0 1-1.487.596c-.566.12-1.163.18-1.79.18a9.916 9.916 0 0 1-1.84-.164 5.544 5.544 0 0 1-1.512-.493v-2.63a5.033 5.033 0 0 0 3.237 1.2c.333 0 .624-.03.872-.09.249-.06.456-.144.623-.25.166-.108.29-.234.373-.38a1.023 1.023 0 0 0-.074-1.089 2.12 2.12 0 0 0-.537-.5 5.597 5.597 0 0 0-.807-.444 27.72 27.72 0 0 0-1.007-.436c-.918-.383-1.602-.852-2.053-1.405-.45-.553-.676-1.222-.676-2.005 0-.614.123-1.141.369-1.582.246-.441.58-.804 1.004-1.089a4.494 4.494 0 0 1 1.47-.629 7.536 7.536 0 0 1 1.77-.201zm-15.113.188h9.563v2.166H9.506v9.646H6.789v-9.646H3.375z" />
+ </svg>
+ );
+}
+
+function BashIcon(props: ComponentProps<"svg">) {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 24 24"
+ fill="currentColor"
+ {...props}
+ >
+ <path d="M21.038 4.9 13.461.402a2.86 2.86 0 0 0-2.923.001L2.961 4.9A3.023 3.023 0 0 0 1.5 7.503v8.995c0 1.073.557 2.066 1.462 2.603l7.577 4.497a2.86 2.86 0 0 0 2.922 0l7.577-4.497a3.023 3.023 0 0 0 1.462-2.603V7.503A3.021 3.021 0 0 0 21.038 4.9zM15.17 18.946l.013.646c.001.078-.05.167-.111.198l-.383.22c-.061.031-.111-.007-.112-.085l-.007-.635c-.328.136-.66.169-.872.084-.04-.016-.057-.075-.041-.142l.139-.584a.24.24 0 0 1 .069-.121.163.163 0 0 1 .036-.026c.022-.011.043-.014.062-.006.229.077.521.041.802-.101.357-.181.596-.545.592-.907-.003-.328-.181-.465-.613-.468-.55.001-1.064-.107-1.072-.917-.007-.667.34-1.361.889-1.8l-.007-.652c-.001-.08.048-.168.111-.2l.37-.236c.061-.031.111.007.112.087l.006.653c.273-.109.511-.138.726-.088.047.012.067.076.048.151l-.144.578a.255.255 0 0 1-.065.116.161.161 0 0 1-.038.028.083.083 0 0 1-.057.009c-.098-.022-.332-.073-.699.113-.385.195-.52.53-.517.778.003.297.155.387.681.396.7.012 1.003.318 1.01 1.023.007.689-.362 1.433-.928 1.888zm3.973-1.087c0 .06-.008.116-.058.145l-1.916 1.164c-.05.029-.09.004-.09-.056v-.494c0-.06.037-.093.087-.122l1.887-1.129c.05-.029.09-.004.09.056v.436zm1.316-11.062-7.168 4.427c-.894.523-1.553 1.109-1.553 2.187v8.833c0 .645.26 1.063.66 1.184a2.304 2.304 0 0 1-.398.039c-.42 0-.833-.114-1.197-.33L3.226 18.64a2.494 2.494 0 0 1-1.201-2.142V7.503c0-.881.46-1.702 1.201-2.142L10.803.863a2.342 2.342 0 0 1 2.394 0l7.577 4.498a2.479 2.479 0 0 1 1.164 1.732c-.252-.536-.818-.682-1.479-.296z" />
+ </svg>
+ );
+}
+
+export function getIconForLanguage(language: string) {
+ switch (language) {
+ case "js":
+ case "jsx":
+ case "ts":
+ case "tsx":
+ case "typescript":
+ return <TypeScriptIcon />;
+ case "bash":
+ case "sh":
+ case "zsh":
+ return <BashIcon />;
+ default:
+ return <FileIcon />;
+ }
+}
diff --git a/components/docs/component-preview.tsx b/components/docs/component-preview.tsx
index 3430056e..33e395d8 100644
--- a/components/docs/component-preview.tsx
+++ b/components/docs/component-preview.tsx
@@ -1,9 +1,9 @@
"use client";
-import { DynamicCodeBlock } from "fumadocs-ui/components/dynamic-codeblock";
import { CheckIcon, LinkIcon, RotateCcwIcon } from "lucide-react";
import { useQueryStates } from "nuqs";
import { Suspense, useEffect, useMemo, useRef, useState } from "react";
+import { CodeBlock } from "@/components/docs/code-block";
import { Button } from "@/components/ui/button";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { useTrackEvent } from "@/lib/analytics";
@@ -130,9 +130,7 @@ function Preview({
</TabsContent>
<TabsContent value="code" className="mt-0">
- <div className="surface-card overflow-hidden rounded-2xl [&_pre]:!rounded-none [&_pre]:!border-0 [&_pre]:!bg-transparent">
- <DynamicCodeBlock lang="tsx" code={code} />
- </div>
+ <CodeBlock code={code} />
</TabsContent>
</Tabs>
diff --git a/components/docs/copy-button.tsx b/components/docs/copy-button.tsx
index f32e635c..276c88ee 100644
--- a/components/docs/copy-button.tsx
+++ b/components/docs/copy-button.tsx
@@ -18,6 +18,7 @@ export function CopyButton({
return (
<Button
+ data-slot="copy-button"
variant="outline"
size="icon-xs"
aria-label="Copy to clipboard"
diff --git a/components/docs/ui-component-preview.tsx b/components/docs/ui-component-preview.tsx
index 3319c744..6454c680 100644
--- a/components/docs/ui-component-preview.tsx
+++ b/components/docs/ui-component-preview.tsx
@@ -1,9 +1,9 @@
"use client";
-import { DynamicCodeBlock } from "fumadocs-ui/components/dynamic-codeblock";
import { CheckIcon, LinkIcon, RotateCcwIcon } from "lucide-react";
import { useQueryStates } from "nuqs";
import { Suspense, useEffect, useMemo, useRef, useState } from "react";
+import { CodeBlock } from "@/components/docs/code-block";
import { Button } from "@/components/ui/button";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { useTrackEvent } from "@/lib/analytics";
@@ -363,9 +363,7 @@ function UiPreview({
</TabsContent>
<TabsContent value="code" className="mt-0">
- <div className="surface-card overflow-hidden rounded-2xl [&_pre]:!rounded-none [&_pre]:!border-0 [&_pre]:!bg-transparent">
- <DynamicCodeBlock lang="tsx" code={code} />
- </div>
+ <CodeBlock code={code} />
</TabsContent>
</Tabs>
diff --git a/mdx-components.tsx b/mdx-components.tsx
index 0a0ffec5..578035e6 100644
--- a/mdx-components.tsx
+++ b/mdx-components.tsx
@@ -1,25 +1,30 @@
import defaultMdxComponents from "fumadocs-ui/mdx";
import type { MDXComponents } from "mdx/types";
+import type { ComponentProps } from "react";
import { BlockPreview } from "@/components/docs/block-preview";
import { Note, Warning } from "@/components/docs/callout";
+import { getIconForLanguage } from "@/components/docs/code-icons";
import { ComponentCardGrid } from "@/components/docs/component-card-grid";
import { ComponentExample } from "@/components/docs/component-example";
import { ComponentPreview } from "@/components/docs/component-preview";
+import { CopyButton } from "@/components/docs/copy-button";
import { Dependencies } from "@/components/docs/dependencies";
import { IconsGallery } from "@/components/docs/icons-gallery";
import { InstallAll } from "@/components/docs/install-all";
import { InstallBlock } from "@/components/docs/install-block";
import { PropsTable } from "@/components/docs/props-table";
import { UiComponentPreview } from "@/components/docs/ui-component-preview";
+import { cn } from "@/lib/utils";
/**
* MDX prose mapping for remocn docs.
*
- * Fumadocs' `defaultMdxComponents` is spread as the base — its machinery must
- * stay intact: heading anchors + scroll IDs (`Heading`), the Shiki
- * `CodeBlock`/`Pre` wiring that emits the `figure.shiki` markup, the
- * internal-aware `Link`, and the overflow-wrapped `Table`. Reimplementing any
- * of these would break code highlighting, copy buttons, and heading deep-links.
+ * Fumadocs' `defaultMdxComponents` is spread as the base — heading anchors +
+ * scroll IDs, the internal-aware `Link`, and the overflow-wrapped `Table` stay
+ * intact. Code blocks are the exception: `source.config.ts` swaps fumadocs'
+ * shiki plugin for rehype-pretty-code (vesper / github-light-default), and the
+ * `pre` / `figcaption` / `code` overrides below render the shadcn-style block
+ * (line numbers, filename title with language icon, copy button).
*
* Docs typography is owned by shadcn typeset (`app/typeset.css`, applied via
* the `typeset typeset-docs` container on the docs page): headings, links,
@@ -30,9 +35,68 @@ import { UiComponentPreview } from "@/components/docs/ui-component-preview";
*
* Custom doc widgets are registered as-is (other lanes own their internals).
*/
+function Pre({ className, ...props }: ComponentProps<"pre">) {
+ return (
+ <pre
+ data-not-typeset
+ className={cn(
+ "no-scrollbar min-w-0 overflow-x-auto px-4 py-3.5 outline-none has-data-line-numbers:px-0",
+ className,
+ )}
+ {...props}
+ />
+ );
+}
+
+function Figcaption({
+ className,
+ children,
+ ...props
+}: ComponentProps<"figcaption">) {
+ const icon =
+ "data-language" in props && typeof props["data-language"] === "string"
+ ? getIconForLanguage(props["data-language"])
+ : null;
+
+ return (
+ <figcaption
+ className={cn(
+ "flex items-center gap-2 text-code-foreground [&_svg]:size-4 [&_svg]:opacity-70",
+ className,
+ )}
+ {...props}
+ >
+ {icon}
+ {children}
+ </figcaption>
+ );
+}
+
+function Code({
+ className,
+ __raw__,
+ ...props
+}: ComponentProps<"code"> & { __raw__?: string }) {
+ if (typeof props.children === "string") {
+ return <code className={className} {...props} />;
+ }
+
+ return (
+ <>
+ {__raw__ ? (
+ <CopyButton value={__raw__} className="absolute top-3 right-2 z-10" />
+ ) : null}
+ <code className={className} {...props} />
+ </>
+ );
+}
+
export function getMDXComponents(components?: MDXComponents): MDXComponents {
return {
...(defaultMdxComponents as MDXComponents),
+ pre: Pre,
+ figcaption: Figcaption,
+ code: Code,
// Custom doc widgets — registrations only, not reimplemented here.
ComponentPreview,
diff --git a/package.json b/package.json
index 0b531712..1ace3c8d 100644
--- a/package.json
+++ b/package.json
@@ -47,6 +47,7 @@
"react": "19.2.4",
"react-dom": "19.2.4",
"react-resizable-panels": "^4.9.0",
+ "rehype-pretty-code": "^0.14.4",
"remotion": "4.0.473",
"server-only": "^0.0.1",
"sonner": "^2.0.7",
diff --git a/source.config.ts b/source.config.ts
index 77a6f7f7..36cb15f4 100644
--- a/source.config.ts
+++ b/source.config.ts
@@ -1,5 +1,7 @@
import { metaSchema, pageSchema } from "fumadocs-core/source/schema";
import { defineConfig, defineDocs } from "fumadocs-mdx/config";
+import rehypePrettyCode from "rehype-pretty-code";
+import type { ShikiTransformer } from "shiki";
export const docs = defineDocs({
dir: "content/docs",
@@ -14,6 +16,35 @@ export const docs = defineDocs({
},
});
+const transformers: ShikiTransformer[] = [
+ {
+ code(node) {
+ if (node.tagName === "code") {
+ node.properties.__raw__ = this.source;
+ if (this.source.split("\n").length > 1) {
+ node.properties["data-line-numbers"] = "";
+ }
+ }
+ },
+ },
+];
+
export default defineConfig({
- mdxOptions: {},
+ mdxOptions: {
+ rehypePlugins: (plugins) => {
+ plugins.shift();
+ plugins.push([
+ rehypePrettyCode,
+ {
+ theme: {
+ dark: "vesper",
+ light: "github-light-default",
+ },
+ keepBackground: false,
+ transformers,
+ },
+ ]);
+ return plugins;
+ },
+ },
});