feat: apply code block background and foreground color
This commit is contained in:
parent
7798d556bc
commit
3711e99528
@ -262,24 +262,36 @@ fn style_declarations(style: &Style) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn generate_css(scopes: &[&str], theme: &Theme) -> 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();
|
let mut groups: HashMap<&Style, Vec<&str>> = HashMap::new();
|
||||||
for &scope in scopes {
|
for &scope in scopes {
|
||||||
if let Some(style) = theme.styles.get(scope) {
|
if let Some(style) = theme.styles.get(scope) {
|
||||||
groups.entry(style).or_default().push(scope);
|
groups.entry(style).or_default().push(scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
groups
|
rules.extend(groups.iter().map(|(style, scopes)| {
|
||||||
.iter()
|
|
||||||
.map(|(style, scopes)| {
|
|
||||||
let selectors = scopes
|
let selectors = scopes
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| scope_to_selector(s))
|
.map(|s| scope_to_selector(s))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(",");
|
.join(",");
|
||||||
format!("{}{{{}}}", selectors, style_declarations(style))
|
format!("{}{{{}}}", selectors, style_declarations(style))
|
||||||
})
|
}));
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join("\n")
|
rules.join("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[func]
|
#[func]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user