diff --git a/src/components/index.tsx b/src/components/index.tsx
index 1d77200..7595742 100644
--- a/src/components/index.tsx
+++ b/src/components/index.tsx
@@ -53,6 +53,7 @@ export { Approval } from "./ui/approval.js";
export { Timeline, Event } from "./ui/timeline.js";
export { Tag, Status } from "./ui/tag.js";
export { Diff } from "./ui/diff.js";
+export { CodeDiff } from "./ui/code-diff.js";
export { Section } from "./ui/section.js";
export { Quote } from "./ui/quote.js";
export { Code } from "./ui/code.js";
diff --git a/src/components/manifest.ts b/src/components/manifest.ts
index 73a8f74..70d1cc5 100644
--- a/src/components/manifest.ts
+++ b/src/components/manifest.ts
@@ -94,6 +94,18 @@ export const componentManifest = [
"\n func handle(w http.ResponseWriter, r *http.Request) { ... }\n"
]
},
+ {
+ "kind": "mdx-component",
+ "name": "CodeDiff",
+ "summary": "Embeds a real code diff inside a document. Wrap a ```diff fenced code block containing a unified patch (e.g. the output of `gh pr diff`), and the host renders it as a full, syntax-highlighted diff view in place of the plain fence.",
+ "category": "data",
+ "spec": {
+ "props": []
+ },
+ "examples": [
+ "\n\n```diff\ndiff --git a/server.go b/server.go\n--- a/server.go\n+++ b/server.go"
+ ]
+ },
{
"kind": "mdx-component",
"name": "Compare",
diff --git a/src/components/ui/code-diff.tsx b/src/components/ui/code-diff.tsx
new file mode 100644
index 0000000..e676049
--- /dev/null
+++ b/src/components/ui/code-diff.tsx
@@ -0,0 +1,40 @@
+import * as React from "react";
+
+/**
+ * Embeds a real code diff inside a document. Wrap a ```diff fenced code
+ * block containing a unified patch (e.g. the output of `gh pr diff`), and
+ * the host renders it as a full, syntax-highlighted diff view in place of
+ * the plain fence.
+ *
+ * This component only emits a marker (`data-slot="code-diff"`) around the
+ * fence — the host (pin) does the diff rendering server-side, so the heavy
+ * lifting stays out of the bundle and the output is static. A plain ```diff
+ * fence without this wrapper is left as ordinary highlighted text.
+ *
+ * @category data
+ * @example
+ *
+ *
+ * ```diff
+ * diff --git a/server.go b/server.go
+ * --- a/server.go
+ * +++ b/server.go
+ * @@ -1,3 +1,4 @@
+ * func main() {
+ * - serve()
+ * + serveTLS()
+ * + log.Println("listening")
+ * }
+ * ```
+ *
+ *
+ */
+function CodeDiff({ children, ...props }: React.ComponentProps<"div">) {
+ return (
+
+ {children}
+
+ );
+}
+
+export { CodeDiff };
diff --git a/test/compile.test.ts b/test/compile.test.ts
index eff19ca..95afe7a 100644
--- a/test/compile.test.ts
+++ b/test/compile.test.ts
@@ -17,6 +17,17 @@ describe("compileMDX", () => {
expect(html).toContain("Heads up");
});
+ it("marks a CodeDiff for host-side diff rendering", () => {
+ const { html } = compileMDX(
+ "\n\n```diff\ndiff --git a/x b/x\n--- a/x\n+++ b/x\n@@ -1 +1 @@\n-old\n+new\n```\n\n",
+ );
+ // Emits the marker the host keys off, wrapping the language-diff fence
+ // with the patch preserved for the host to render.
+ expect(html).toContain(`data-slot="code-diff"`);
+ expect(html).toContain(`class="language-diff"`);
+ expect(html).toContain("diff --git a/x b/x");
+ });
+
it("renders nested components", () => {
const { html } = compileMDX(
``,
diff --git a/test/manifest.test.ts b/test/manifest.test.ts
index a46088d..c1e369f 100644
--- a/test/manifest.test.ts
+++ b/test/manifest.test.ts
@@ -2,8 +2,14 @@ import { describe, it, expect } from "vitest";
import { componentManifest } from "../src/components/manifest.js";
describe("componentManifest", () => {
- it("contains all 29 user-facing components", () => {
- expect(componentManifest.length).toBe(29);
+ it("contains all 30 user-facing components", () => {
+ expect(componentManifest.length).toBe(30);
+ });
+
+ it("includes CodeDiff in the data category", () => {
+ const c = componentManifest.find((e) => e.name === "CodeDiff");
+ expect(c).toBeDefined();
+ expect(c!.category).toBe("data");
});
it("includes Subagent in the agent category", () => {