Server code block
A code block highlighted in a React Server Component.
const greeting = "Hello, world!";Installation
npx shadcn@latest add @docscn/server-codeblockUsage
import { ServerCodeBlock } from "@/components/docs/components/codeblock.rsc";
<ServerCodeBlock lang="ts" code={code} />;ServerCodeBlock is an async React Server Component. It highlights the code with Shiki on the server, using the same code block as your content, and sends no highlighting code to the browser.
For code that's only known in the browser, use DynamicCodeBlock.
Your own highlighter
createServerCodeBlock creates a server code block that highlights with your own highlighter, such as one with other themes or Shiki options:
import { createServerCodeBlock } from "@/components/docs/components/codeblock.rsc";
import { createShikiHighlighter } from "fumadocs-core/highlight/shiki";
import { defaultShikiFactory } from "fumadocs-core/highlight/shiki/full";
const highlighter = createShikiHighlighter(
() => defaultShikiFactory.getOrInit(),
{
themes: { light: "github-light", dark: "github-dark" },
// the code block colours tokens with CSS variables
defaultColor: false,
},
);
export const ServerCodeBlock = createServerCodeBlock({ highlighter });It takes lang, code and codeblock. See Highlighter in Fumadocs' docs for the highlighters Fumadocs Core can create.
Props
Prop
Type