diff --git a/src/themes.rs b/src/themes.rs index 147d6b2..2ed442e 100644 --- a/src/themes.rs +++ b/src/themes.rs @@ -262,24 +262,36 @@ fn style_declarations(style: &Style) -> String { } fn generate_css(scopes: &[&str], theme: &Theme) -> String { + let mut rules = Vec::new(); + + // The theme's editor foreground/background colour the code block itself. + let mut block_style = Vec::new(); + if let Some(Color(hex)) = &theme.foreground { + block_style.push(format!("color:{hex}")); + } + if let Some(Color(hex)) = &theme.background { + block_style.push(format!("background:{hex}")); + } + if !block_style.is_empty() { + rules.push(format!(".code-block{{{}}}", block_style.join(";"))); + } + let mut groups: HashMap<&Style, Vec<&str>> = HashMap::new(); for &scope in scopes { if let Some(style) = theme.styles.get(scope) { groups.entry(style).or_default().push(scope); } } - groups - .iter() - .map(|(style, scopes)| { - let selectors = scopes - .iter() - .map(|s| scope_to_selector(s)) - .collect::>() - .join(","); - format!("{}{{{}}}", selectors, style_declarations(style)) - }) - .collect::>() - .join("\n") + rules.extend(groups.iter().map(|(style, scopes)| { + let selectors = scopes + .iter() + .map(|s| scope_to_selector(s)) + .collect::>() + .join(","); + format!("{}{{{}}}", selectors, style_declarations(style)) + })); + + rules.join("\n") } #[func]