Example: Code Syntax Highlighting

Zola comes with built-in syntax highlighting powered by syntect. This post demonstrates how to include code blocks with syntax highlighting in your Markdown content.

Basic Code Block

To create a simple code block, use triple backticks (```) with the language identifier:

def hello_world():
    print("Hello, Zola!")
    
hello_world()

Supported Languages

Zola supports a wide range of programming languages. Here are a few examples:

JavaScript

function toggleDarkMode() {
  const body = document.body;
  body.classList.toggle('dark');
  body.classList.toggle('light');
  
  // Save preference to localStorage
  const isDark = body.classList.contains('dark');
  localStorage.setItem('darkMode', isDark);
}

CSS

:root {
  --primary-color: #ff2e88;
  --secondary-color: #b7005d;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem;
}

Rust

fn main() {
    let greeting = "Hello, Zola!";
    println!("{}", greeting);
    
    // Using Zola for static site generation
    let features = vec!["Fast", "Simple", "Flexible"];
    for feature in features {
        println!("Zola is {}!", feature);
    }
}

Inline Code

You can also use inline code with single backticks.

Line Numbers

Zola automatically adds line numbers to code blocks for better readability.