Code Block
Provides syntax highlighting, line numbers, and copy to clipboard functionality for code blocks.
Powered by
Installation
npx pal-ui@latest add code-block
Features
- Syntax highlighting
- Line numbers
- Copy to clipboard
- Support for filenames
- Highlighted lines and words
- Focused line
- Diff
- Language detection
- Theme support
- Customizable styles
Examples
No header
Highlighted lines
Highlighted words
Diff
Focus
Hidden line numbers
No syntax highlighting
Custom Theme
Notes
React Server Component
You can use the RSC version of the Code Block component by importing the CodeBlockContent
component from code-block/server
i.e.
import {
CodeBlock,
CodeBlockHeader,
// ... the rest of the components
CodeBlockBody,
// CodeBlockContent,
} from '@/components/pal-ui/code-block';
import { CodeBlockContent } from '@/components/pal-ui/code-block/server';