Code syntax highlighting in Markdown to PDF
Fenced blocks in 14 languages and their variants are colored with editor palettes and stay selectable text in the PDF. Long lines wrap instead of running off the page.
Fenced blocks in 14 languages and their variants such as TypeScript and Kotlin, colored with the familiar editor palettes. Toggle: highlight (off: plain mono).
Markdown source
Markdown · 73 lines# Syntax highlighting
```python
from dataclasses import dataclass
@dataclass
class Shipment:
reference: str
mass_kg: float
def freight(self, rate_per_kg: float) -> float:
"""Freight charge, rounded to the cent."""
return round(self.mass_kg * rate_per_kg, 2)
```
```typescript
export async function fetchRates(currency: string): Promise<Map<string, number>> {
const res = await fetch(`https://api.example.com/rates?base=${currency}`);
if (!res.ok) throw new Error(`rates: ${res.status}`);
const { rates } = (await res.json()) as { rates: Record<string, number> };
return new Map(Object.entries(rates));
}
```
```go
func median(xs []float64) float64 {
sort.Float64s(xs)
n := len(xs)
if n%2 == 1 {
return xs[n/2]
}
return (xs[n/2-1] + xs[n/2]) / 2 // even count: mean of the middle pair
}
```
```rust
fn checksum(digits: &str) -> Option<u8> {
let sum: u32 = digits.bytes().rev().enumerate()
.map(|(i, b)| (b - b'0') as u32 * if i % 2 == 0 { 3 } else { 1 })
.sum();
Some(((10 - sum % 10) % 10) as u8)
}
```
```sql
SELECT region, SUM(units) AS units, AVG(unit_price) AS avg_price
FROM sales
WHERE sold_at >= DATE '2026-01-01'
GROUP BY region
HAVING SUM(units) > 1000
ORDER BY units DESC;
```
```yaml
service: warehouse-sync
schedule: "0 */6 * * *"
retries: 3
regions: [eu-west, ap-south]
```
```bash
#!/usr/bin/env bash
set -euo pipefail
for f in reports/*.md; do
echo "converting ${f}"
done
```
```json
{ "order": "A-4172", "items": 3, "express": true, "total": 184.5 }
```
A fence without a language tag stays plain mono, and a language the highlighter does not know prints plain as well.
Rendered pages
PDF · 2 pages · 17 KBThe sample documents describe invented organizations in several countries. All names and figures are illustrative.
Code blocks with syntax highlighting in PDF: every sampleIn the Markdown reference

