Zola Syntax Highlighting
Table of Contents
Zola comes with built-in syntax highlighting but you first need to enable it in the configuration.
Annotations
You can use additional annotations to customize how code blocks are displayed:
linenos
to enable line numbering.
```rust,linenos
use highlighter::highlight;
use std::env;
let code = "...";
highlight(code);
fn foo(bar: i32) {
println!("{}", bar);
let baz = bar + 42;
println!("{}", baz);
println!("{}", baz * 3.14);
}
```
1 use highlighter::highlight;
2 use std::env;
3 let code = "...";
4 highlight(code);
5 fn foo(bar: i32) {
6 println!("{}", bar);
7 let baz = bar + 42;
8 println!("{}", baz);
9 println!("{}", baz * 3.14);
10 }
linenostart
to specify the number for the first line (defaults to 1)
```rust,linenos,linenostart=20
use highlighter::highlight;
use std::env;
let code = "...";
highlight(code);
fn foo(bar: i32) {
println!("{}", bar);
let baz = bar + 42;
println!("{}", baz);
println!("{}", baz * 3.14);
}
```
20 use highlighter::highlight;
21 use std::env;
22 let code = "...";
23 highlight(code);
24 fn foo(bar: i32) {
25 println!("{}", bar);
26 let baz = bar + 42;
27 println!("{}", baz);
28 println!("{}", baz * 3.14);
29 }
hl_lines
to highlight lines. You must specify a list of inclusive ranges of lines to highlight, separated bylinenostart
doesn't influence the values, it always refers to the codeblock line number.
```rust,hl_lines=1 3-5 9
use highlighter::highlight;
use std::env;
let code = "...";
highlight(code);
fn foo(bar: i32) {
println!("{}", bar);
let baz = bar + 42;
println!("{}", baz);
println!("{}", baz * 3.14);
}
```
use highlighter::highlight;
use std::env;
let code = "...";
highlight(code);
fn foo(bar: i32) {
println!("{}", bar);
let baz = bar + 42;
println!("{}", baz);
println!("{}", baz * 3.14);
}
hide_lines
to hide lines. You must specify a list of inclusive ranges of lines to hide, separated by
```rust,hide_lines=1-2
use highlighter::highlight;
use std::env;
let code = "...";
highlight(code);
fn foo(bar: i32) {
println!("{}", bar);
let baz = bar + 42;
println!("{}", baz);
println!("{}", baz * 3.14);
}
```
let code = "...";
highlight(code);
fn foo(bar: i32) {
println!("{}", bar);
let baz = bar + 42;
println!("{}", baz);
println!("{}", baz * 3.14);
}