summaryrefslogtreecommitdiffstats
path: root/src/render/markdown.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2023-03-11 18:53:36 +0800
committerGitHub <noreply@github.com>2023-03-11 18:53:36 +0800
commitcfb6ce6958751da5e13683ea07f42a5dbc4eae01 (patch)
treec7ec60ba7c1d2e37225ae6b1476057a18e2eb987 /src/render/markdown.rs
parentdc09cb38d480342c9fe781a19fe72d2bb892b70c (diff)
downloadaichat-cfb6ce6958751da5e13683ea07f42a5dbc4eae01.tar.gz
feat: support light theme (#65)
There are two ways to enable the light theme: - add `light_theme: true` to config.yaml - use `AICHAT_LIGHT_THEME=true` env var
Diffstat (limited to 'src/render/markdown.rs')
-rw-r--r--src/render/markdown.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/render/markdown.rs b/src/render/markdown.rs
index affaf21..5bdca9d 100644
--- a/src/render/markdown.rs
+++ b/src/render/markdown.rs
@@ -7,6 +7,7 @@ use syntect::{easy::HighlightLines, parsing::SyntaxReference};
/// Monokai Extended
const MD_THEME: &[u8] = include_bytes!("../../assets/monokai-extended.theme.bin");
+const MD_THEME_LIGHT: &[u8] = include_bytes!("../../assets/monokai-extended-light.theme.bin");
/// Comes from https://github.com/sharkdp/bat/raw/5e77ca37e89c873e4490b42ff556370dc5c6ba4f/assets/syntaxes.bin
const SYNTAXES: &[u8] = include_bytes!("../../assets/syntaxes.bin");
@@ -29,10 +30,14 @@ pub struct MarkdownRender {
}
impl MarkdownRender {
- pub fn new() -> Self {
+ pub fn new(light_theme: bool) -> Self {
let syntax_set: SyntaxSet =
bincode::deserialize_from(SYNTAXES).expect("invalid syntaxes binary");
- let md_theme: Theme = bincode::deserialize_from(MD_THEME).expect("invalid md_theme binary");
+ let md_theme: Theme = if light_theme {
+ bincode::deserialize_from(MD_THEME_LIGHT).expect("invalid theme binary")
+ } else {
+ bincode::deserialize_from(MD_THEME).expect("invalid theme binary")
+ };
let code_color = get_code_color(&md_theme);
let md_syntax = syntax_set.find_syntax_by_extension("md").unwrap().clone();
let line_type = LineType::Normal;
@@ -223,7 +228,7 @@ mod tests {
#[test]
fn test_render() {
- let render = MarkdownRender::new();
+ let render = MarkdownRender::new(true);
assert!(render.find_syntax("csharp").is_some());
}
}