Skip to content

Commit

Permalink
Do not assume themes are present for CSS export
Browse files Browse the repository at this point in the history
Closes #1884
  • Loading branch information
Keats committed Jun 10, 2022
1 parent 3c54019 commit 0949007
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions components/config/src/config/markup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ impl Markdown {
if self.highlight_theme == "css" {
None
} else {
Some(self.get_highlight_theme_by_name(&self.highlight_theme))
self.get_highlight_theme_by_name(&self.highlight_theme)
}
}

/// Gets an arbitrary theme from the THEME_SET or the extra_theme_set
pub fn get_highlight_theme_by_name(&self, theme_name: &str) -> &Theme {
pub fn get_highlight_theme_by_name(&self, theme_name: &str) -> Option<&Theme> {
(*self.extra_theme_set)
.as_ref()
.and_then(|ts| ts.themes.get(theme_name))
.unwrap_or_else(|| &THEME_SET.themes[theme_name])
.or_else(|| THEME_SET.themes.get(theme_name))
}

/// Attempt to load any extra syntaxes and themes found in the extra_syntaxes_and_themes folders
Expand All @@ -95,9 +95,12 @@ impl Markdown {
))
}

pub fn export_theme_css(&self, theme_name: &str) -> String {
let theme = self.get_highlight_theme_by_name(theme_name);
css_for_theme_with_class_style(theme, CLASS_STYLE).expect("the function can't even error?")
pub fn export_theme_css(&self, theme_name: &str) -> Result<String> {
if let Some(theme) = self.get_highlight_theme_by_name(theme_name) {
Ok(css_for_theme_with_class_style(theme, CLASS_STYLE).expect("the function can't even error?"))
} else {
bail!("Theme {} not found", theme_name)
}
}

pub fn init_extra_syntaxes_and_highlight_themes(&mut self, path: &Path) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion components/site/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ impl Site {
for t in &self.config.markdown.highlight_themes_css {
let p = self.static_path.join(&t.filename);
if !p.exists() {
let content = &self.config.markdown.export_theme_css(&t.theme);
let content = &self.config.markdown.export_theme_css(&t.theme)?;
create_file(&p, content)?;
}
}
Expand Down

0 comments on commit 0949007

Please sign in to comment.