
3 min read
Code Block Showcase
This article demonstrates how our code blocks render with different languages, line numbers, long lines, wrapping, and dark/light modes.
Note: Each block shows the header with language and the copy action. Line numbers are enabled globally in our
CodeBlock.
JavaScript (standard)
JavaScript
import React, { useState } from 'react'
function Counter() {
const [count, setCount] = useState(0)
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>Click me</button>
</div>
)
}
export default Counter
TypeScript (interfaces)
TypeScript
interface User {
id: string
name: string
email?: string
}
function greet(user: User): string {
return `Hello, ${user.name}!`
}
export { greet }
Python
Python
def fibonacci(n: int):
"""Generate Fibonacci sequence up to n terms"""
sequence = []
a, b = 0, 1
while len(sequence) < n:
sequence.append(a)
a, b = b, a + b
return sequence
print(fibonacci(10))
Shell (zsh)
Shell
# List all files including dotfiles
ls -la
# Create a folder and move into it
mkdir demo && cd demo
JSON
JSON
{
"name": "demo",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "next dev"
}
}
YAML
YAML
name: CI
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
HTML
HTML
<section class="hero">
<h1>Welcome</h1>
<p>Minimal example</p>
</section>
CSS
CSS
:root {
--brand: #2563eb;
}
.button {
background: var(--brand);
color: #fff;
border-radius: 0.5rem;
}
Long lines and horizontal scroll
TypeScript
// A very long line that should scroll horizontally without breaking the layout or overflowing the container on small screens — this line intentionally exceeds typical widths to validate the scroll behavior in our CodeBlock implementation
const url = "https://example.com/some/really/long/path/with/many/segments/and/query?param1=one¶m2=two¶m3=three¶m4=four¶m5=five¶m6=six";
With backticks and special characters
Markdown
This code block is fenced by triple backticks inside Markdown — useful to test escaping.
Code
No language (plain)
Code
This code block has no language hint. It should still render with header labeled as "Code" and allow copying.
Line 2
Line 3
JSX (TSX)
TSX
import type { FC } from 'react'
type Props = { label: string }
const Button: FC<Props> = ({ label }) => (
<button className="rounded bg-blue-600 px-3 py-1 text-white">{label}</button>
)
export default Button
SQL
SQL
SELECT id, name, created_at
FROM users
WHERE active = true
ORDER BY created_at DESC
LIMIT 10;
Rust
Rust
fn main() {
println!("Hello, world!");
}
Go
Go
package main
import "fmt"
func main() {
fmt.Println("Hello, Go")
}
Edge cases: leading/trailing newlines
JavaScript
console.log('Leading blank line preserved')
Python
print('Trailing newline preserved')\n
That’s it! Toggle dark/light mode to see how tokens and backgrounds adapt while line numbers stay crisp and readable.