Components
Display syntax-highlighted code with copy functionality
The <CodeBlock> component displays single code snippets with syntax highlighting, optional filename headers, and copy-to-clipboard functionality.
Standard markdown code blocks automatically use CodeBlock:
```javascript
const greeting = "Hello, World!";
console.log(greeting);
```
const greeting = "Hello, World!";
console.log(greeting);
Add a filename to the code block header:
```typescript filename="src/app.ts"
import express from "express";
const app = express();
app.listen(3000);
```
CodeBlock supports 200+ programming languages through Shiki:
Powered by Shiki with accurate, theme-aware highlighting:
interface User {
id: string;
email: string;
role: "admin" | "user";
}
const user: User = {
id: "123",
email: "user@example.com",
role: "user",
};
Every code block includes a copy button in the top-right corner for easy code copying.
Code blocks automatically switch between light and dark themes based on your site's color mode.
// Async/await example
async function fetchUser(id) {
const response = await fetch(`/api/users/${id}`);
return response.json();
}
# List comprehension
squares = [x**2 for x in range(10)]
# Dictionary
user = {
"name": "John Doe",
"email": "john@example.com"
}
{
"name": "My App",
"version": "1.0.0",
"dependencies": {
"react": "^18.2.0",
"next": "^14.0.0"
}
}
# Install dependencies
npm install
# Run development server
npm run dev
# Build for production
npm run build
SELECT
users.id,
users.name,
COUNT(orders.id) as order_count
FROM users
LEFT JOIN orders ON users.id = orders.user_id
GROUP BY users.id, users.name
HAVING COUNT(orders.id) > 5;
Use single backticks for inline code: const x = 42;
Specify the correct language for accurate highlighting:
Good: ```typescript
Avoid: ```text or ``` (no language)
Next, learn about the Changelog Component for release notes.