Code Blocks
Syntax highlighting, filename titles, highlighted lines, line numbers, wrap toggle and Mermaid diagrams.
Highlighting happens at build time via Hugo’s Chroma engine, so no JavaScript is needed for colors. The palette follows the active theme. Every block gets a copy button and a line-wrap toggle in its header bar automatically.
Language badge
```go
package main
func main() {
println("hello")
}
```package main
func main() {
println("hello")
}Filename title
```go {title="main.go"}
package main // the bar shows main.go next to the language badge
```package main // the bar shows main.go next to the language badgeHighlighted lines
```yaml {title="site.json themes" hl_lines=[2,3]}
themes:
- id: light # these two lines
default: true # are highlighted
- id: dark
```themes:
- id: light # these two lines
default: true # are highlighted
- id: darkLine numbers
```bash {linenos=true}
hugo mod get gitlab.com/natitec_public/bora
hugo server
```
|
|
Wrap toggle
Click the wrap button (left of copy) on this block. The long line soft-wraps instead of scrolling:
This deliberately long single line would normally force a horizontal scrollbar inside the code block unless the wrap toggle is switched on, in which case it wraps within the block borders.Mermaid diagrams
A ```mermaid block renders as a diagram. The renderer loads only on pages that use it and re-renders when the theme switches:
flowchart LR
A[Markdown] --> B(Chroma)
B --> C{Theme CSS}
C -->|light| D[GitHub palette]
C -->|dark| E[Dark palette]
Combining options
All options combine freely on one block:
```yaml {title="example.yaml" hl_lines=[2] linenos=true}
key: value
highlighted: true
another: value
```
|
|
Was this page helpful?
Thanks for your feedback!