Merge pull request #416 from porglezomp-misc/background-color

Change highlighting to not include duplicated background colors
This commit is contained in:
Vincent Prouillet 2018-09-10 09:16:37 +02:00 committed by GitHub
commit 352cb17586
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -51,6 +51,7 @@ pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result<Render
// Set while parsing // Set while parsing
let mut error = None; let mut error = None;
let mut background = IncludeBackground::Yes;
let mut highlighter: Option<HighlightLines> = None; let mut highlighter: Option<HighlightLines> = None;
// If we get text in header, we need to insert the id and a anchor // If we get text in header, we need to insert the id and a anchor
let mut in_header = false; let mut in_header = false;
@ -93,7 +94,7 @@ pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result<Render
// if we are in the middle of a code block // if we are in the middle of a code block
if let Some(ref mut highlighter) = highlighter { if let Some(ref mut highlighter) = highlighter {
let highlighted = &highlighter.highlight(&text); let highlighted = &highlighter.highlight(&text);
let html = styles_to_coloured_html(highlighted, IncludeBackground::Yes); let html = styles_to_coloured_html(highlighted, background);
return Event::Html(Owned(html)); return Event::Html(Owned(html));
} }
@ -107,7 +108,12 @@ pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result<Render
let theme = &THEME_SET.themes[&context.config.highlight_theme]; let theme = &THEME_SET.themes[&context.config.highlight_theme];
match get_highlighter(&theme, info, context.base_path, &context.config.extra_syntaxes) { match get_highlighter(&theme, info, context.base_path, &context.config.extra_syntaxes) {
Ok(h) => highlighter = Some(h), Ok(h) => {
highlighter = Some(h);
// This selects the background color the same way that start_coloured_html_snippet does
let color = theme.settings.background.unwrap_or(::syntect::highlighting::Color::WHITE);
background = IncludeBackground::IfDifferent(color);
}
Err(err) => { Err(err) => {
error = Some(format!("Could not load syntax: {}", err).into()); error = Some(format!("Could not load syntax: {}", err).into());
return Event::Html(Borrowed("")); return Event::Html(Borrowed(""));