23 lines
704 B
Rust
23 lines
704 B
Rust
use std::fs;
|
|
use std::path::PathBuf;
|
|
|
|
use syntect::highlighting::ThemeSet;
|
|
use syntect::html::highlighted_html_for_string;
|
|
use syntect::parsing::SyntaxSet;
|
|
|
|
pub fn get_pretty_body(path: &PathBuf, ext: &String) -> String {
|
|
let ss = SyntaxSet::load_defaults_newlines();
|
|
|
|
let mut theme_cursor =
|
|
std::io::Cursor::new(include_bytes!("../../themes/ayu_dark.tmTheme"));
|
|
let theme = ThemeSet::load_from_reader(&mut theme_cursor).unwrap();
|
|
|
|
let content = fs::read_to_string(path).unwrap();
|
|
let syntax = ss
|
|
.find_syntax_by_token(ext)
|
|
.unwrap_or_else(|| ss.find_syntax_plain_text());
|
|
let html = highlighted_html_for_string(&content, &ss, syntax, &theme);
|
|
|
|
html
|
|
}
|