Code
Use fenced code blocks with a language identifier for syntax highlighting:
```rust
fn main() {
println!("Hello!");
}
```Renders as:
fn main() {
println!("Hello!");
}Supported Languages
Syntax highlighting is powered by PrismJS. We're still expanding the set of supported languages — if yours isn't highlighted yet, it will be soon.
Ping us on Discord if the language you need is missing!
Meta Attributes
You can add attributes after the language identifier to control how the block looks. Use key=value syntax, separated by spaces:
| Attribute | Description | Example |
|---|---|---|
file | Display a filename badge | file=parser.rs |
highlight | Highlight specific lines | highlight=3,5-8,12 |
caption | Add a description below the block | caption="Error handling logic" |
Filename
Shows a filename badge in the code block header:
```rust file=src/main.rs
fn main() {
let config = Config::load();
run(config);
}
```Renders as:
fn main() {
let config = Config::load();
run(config);
}Line Highlighting
Highlight specific lines to draw attention to important parts:
```python highlight=3-4
def greet(name):
"""Say hello."""
message = f"Hello, {name}!"
print(message)
```Renders as:
def greet(name):
"""Say hello."""
message = f"Hello, {name}!"
print(message)| Format | Example | Description |
|---|---|---|
| Single line | highlight=5 | Highlights line 5 |
| Range | highlight=10-15 | Highlights lines 10 through 15 |
| Mixed | highlight=2,5-8,12 | Combines singles and ranges |
Caption
Captions show up below the code block:
```javascript file=api.js highlight=4 caption="User fetching and parsing"
async function fetchUser(id) {
const response = await fetch("/api/users/" + id);
const data = await response.json();
return User.parse(data);
}
```Renders as:
async function fetchUser(id) {
const response = await fetch("/api/users/" + id);
const data = await response.json();
return User.parse(data);
}UI Features
Every code block comes with a copy button and a language badge. If the block has a block ID, there's also a link button so readers can grab a direct link to it.