Highlight Code In Rust With syntect

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

use syntect::highlighting::ThemeSet;
use syntect::html::highlighted_html_for_string;
use syntect::parsing::SyntaxSet;

fn main() {
    let code = r#"<p>a
    b
    c
    </p>"#;
    let output = highlight_html(code);
    println!("{}", output)
}

pub fn highlight_html(name: &str) -> String {
    let ss = SyntaxSet::load_defaults_nonewlines();
    let ts = ThemeSet::load_defaults();
    let theme = &ts.themes["base16-ocean.dark"];
    let html = highlighted_html_for_string(name, &ss, &ss.syntaxes()[1], theme).unwrap();
    html
}
TODO: Show Results Output

This is the version from the docs for testing newline stuff I'm trying to figure out.

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

use syntect::easy::HighlightLines;
use syntect::parsing::SyntaxSet;
use syntect::highlighting::{ThemeSet, Style};
use syntect::util::{as_24_bit_terminal_escaped, LinesWithEndings};

fn main () {
// Load these once at the start of your program
let ps = SyntaxSet::load_defaults_newlines();
let ts = ThemeSet::load_defaults();

let syntax = ps.find_syntax_by_extension("rs").unwrap();
let mut h = HighlightLines::new(syntax, &ts.themes["base16-ocean.dark"]);
let s = "pub struct Wow { hi: u64 }\nfn blah() -> u64 {}";
for line in LinesWithEndings::from(s) { // LinesWithEndings enables use of newlines mode
    let ranges: Vec<(Style, &str)> = h.highlight_line(line, &ps).unwrap();
    let escaped = as_24_bit_terminal_escaped(&ranges[..], true);
    print!("{}", escaped);
}
}
TODO: Show Results Output

Notes

~ fin ~

References