Code block
Code blocks and code tabs for Shiki output.
Installation
npx shadcn@latest add @docscn/codeblockUsage
defaultMdxComponents renders every code block in your MDX with CodeBlock. Fumadocs MDX's syntax works as usual:
```ts title="greet.ts"
export function greet(name: string) {
return `Hello, ${name}!`; // [\!code highlight]
}
```export function greet(name: string) {
return `Hello, ${name}!`;
}title="..."adds a title bar, with an icon for the language.- The copy button copies the code.
- Shiki's notations add highlighted (
[!code highlight]), added and removed ([!code ++],[!code --]), focused ([!code focus]) and highlighted-word ([!code word:x]) styles, andlineNumbersshows line numbers.
Code blocks with tab="..." and ```npm blocks become code tabs, on shadcn/ui tabs:
npm install next-themesProps
Prop
Type
CodeBlockTabs also accepts groupId and persist, to keep the same tab selected across code tabs and page loads.
The component's CSS (the light and dark Shiki themes and the notation styles) was added to your global stylesheet. Add not-docs-codeblock to an element to opt it out.