1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
// Copyright (C) 2023 Enrico Guiraud
//
// This file is part of highlight-pulldown.
//
// highlight-pulldown is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// highlight-pulldown is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with highlight-pulldown. If not, see <http://www.gnu.org/licenses/>.
use highlight_pulldown::highlight_with_theme;
fn main() {
let markdown = r#"# Hello syntax highlighting
Here's some Python code:
```python
print("foo", 42)
```
And here's some Rust code:
```rust
enum Hello {
World,
SyntaxHighlighting,
}
```
"#;
let events = pulldown_cmark::Parser::new(markdown);
// The themes available are the same as in syntect:
// - base16-ocean.dark,base16-eighties.dark,base16-mocha.dark,base16-ocean.light
// - InspiredGitHub
// - Solarized (dark) and Solarized (light)
// The default theme is the same as in syntect: "base16-ocean.dark".
// See also https://docs.rs/syntect/latest/syntect/highlighting/struct.ThemeSet.html#method.load_defaults .
let events = highlight_with_theme(events, "base16-ocean.dark").unwrap();
let mut html = String::new();
pulldown_cmark::html::push_html(&mut html, events.into_iter());
let expected = r#"<pre style="background-color:#2b303b;">
<span style="color:#c0c5ce;"> ```python
</span><span style="color:#c0c5ce;"> print("foo", 42)
</span><span style="color:#c0c5ce;"> ```
</span></pre>
"#;
assert_eq!(html, expected);
}