refactor: bring in the modules

Signed-off-by: Gunwant Jain <mail@wantguns.dev>
This commit is contained in:
Gunwant Jain
2021-07-11 03:07:50 +05:30
parent 8a3b29a0ef
commit 9c5a3af128
12 changed files with 145 additions and 118 deletions

18
src/models/pretty.rs Normal file
View File

@@ -0,0 +1,18 @@
use std::fs;
use syntect::highlighting::ThemeSet;
use syntect::html::highlighted_html_for_string;
use syntect::parsing::SyntaxSet;
pub fn get_pretty_body(path: &String, ext: &String) -> String {
let ss = SyntaxSet::load_defaults_newlines();
let theme = ThemeSet::get_theme("themes/ayu_dark.tmTheme").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
}