html/
html.rs

1use pygmentize::{highlight, HtmlFormatter};
2use std::fs;
3
4fn main() {
5    let fmt = HtmlFormatter {
6        line_numbers: true,
7        ..HtmlFormatter::default()
8    };
9
10    let code = include_str!("html.rs");
11    let html = highlight(code, Some("rust"), &fmt).unwrap();
12    println!("{html}");
13
14    // dracula.css is Dracula for Pygments
15    // https://draculatheme.com/pygments
16    let html = format!(
17        r#"<!DOCTYPE html>
18<html lang="en-US">
19<head>
20    <style>
21        body {{
22            color: #f8f8f2;
23            background: #44475a;
24        }}
25
26        .highlight, .code {{
27            background: #282a36;
28        }}
29
30        .linenos {{
31            background: #44475a;
32        }}
33    </style>
34    <link rel="stylesheet" href="dracula.css">
35</head>
36<body>
37    {}
38</body>
39</html>"#,
40        html
41    );
42    fs::write("index.html", html).unwrap();
43}