carbon_lib/utils/
config.rs1use crate::{CarbonError, CarbonResult};
2use carbon_dump::{SYNTAX_SET, THEME_SET};
3use syntect::{highlighting::Theme, parsing::SyntaxReference};
4
5pub struct Render {
6 pub(crate) theme: Theme,
7 pub(crate) syntax: SyntaxReference,
8 pub html_style: String,
9 pub html_type: CarbonHTML,
10 pub file_title: Option<String>,
11 pub line_number: Option<usize>,
12}
13
14pub enum CarbonHTML {
15 Inline,
17 Embedded,
19 Independent,
21}
22
23impl Default for Render {
24 fn default() -> Self {
25 let theme = THEME_SET.themes.get("one-dark").unwrap();
26 let syntax = SYNTAX_SET.find_syntax_by_extension("rs").unwrap();
27 Self {
28 syntax: syntax.clone(),
29 theme: theme.clone(),
30 html_style: String::from(include_str!("render.css")),
31 html_type: CarbonHTML::Independent,
32 file_title: None,
33 line_number: None,
34 }
35 }
36}
37
38impl Render {
39 pub fn set_theme(&mut self, s: &str) -> CarbonResult<()> {
40 let theme = THEME_SET.themes.get(s).ok_or(CarbonError::ThemeNotFound(s.to_string()))?;
41 self.theme = theme.clone();
42 Ok(())
43 }
44
45 pub fn set_syntax(&mut self, s: &str) -> CarbonResult<()> {
46 let syntax = SYNTAX_SET.find_syntax_by_extension(s).ok_or(CarbonError::SyntaxNotFound(s.to_string()))?;
47 self.syntax = syntax.clone();
48 Ok(())
49 }
50}