rust
```cargo
[dependencies]
syntect = "5.2.0"
```
use syntect::html::{ClassedHTMLGenerator, ClassStyle};
use syntect::parsing::SyntaxSet;
use syntect::util::LinesWithEndings;
fn main() {
let code = r#"fn main() {
println!("Hello, World");
}"#;
let lang = "rust";
let output = highlight_code(code, lang);
println!("{}", output)
}
fn highlight_code(code: &str, lang: &str) -> String {
let syntax_set = SyntaxSet::load_defaults_newlines();
let syntax = syntax_set.find_syntax_by_token(&lang).unwrap_or_else(|| syntax_set.find_syntax_plain_text());
let mut html_generator = ClassedHTMLGenerator::new_with_class_style(syntax, &syntax_set, ClassStyle::Spaced);
for line in LinesWithEndings::from(code) {
let _ = html_generator.parse_html_for_line_which_includes_newline(line);
}
let output_html = html_generator.finalize();
format!(r#"<pre><code>{}</code></pre>"#, output_html)
}
results start
This does classes instead of hard coded values
for the styling.