Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Generate Syntax Highlighting CSS For Classed Based Output Of The syntect Crate In Rust

rust
```cargo
[dependencies]
syntect = "5.2.0"
```

use syntect::highlighting::ThemeSet;
use syntect::html::ClassStyle;
use syntect::html::css_for_theme_with_class_style;


fn main() {
  let css = generate_css("Solarized (dark)");
  println!("{}", css);
}


fn generate_css(theme: &str) -> String {
  let ts = ThemeSet::load_defaults();
  if ts.themes.contains_key(theme) {
    let theme = &ts.themes[theme];
    match css_for_theme_with_class_style(theme, ClassStyle::Spaced) {
      Ok(css) => css,
      Err(_) => format!("/* could not load theme: {:?} */", theme)
    }
  } else  {
    format!("/* No theme available in syntect named: {:?} */", theme)
  }
}
results start

I like using classes instead of inline styles 1 when doing syntax highlighting use syntect 2 . This is the code I use to generate the style sheet that goes along with the highlighted code :

Footnotes And References