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);
}
```
1use highlighter::highlight;
2use std::env;
3let code = "...";
4highlight(code);
5fn 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);
}
```
20use highlighter::highlight;
21use std::env;
22let code = "...";
23highlight(code);
24fn 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 by (whitespace). Ranges are 1-indexed and linenostart 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 (whitespace). Ranges are 1-indexed.
```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);
}