Skip to Content
docscn

Code block

Code blocks and code tabs for Shiki output.

Installation

npx shadcn@latest add @docscn/codeblock

Usage

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]
}
```
greet.ts
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, and lineNumbers shows line numbers.

Code blocks with tab="..." and ```npm blocks become code tabs, on shadcn/ui tabs:

npm install next-themes

Props

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.