diff --git a/src/config.rs b/src/config.rs index b87ad27644..23a6d3a221 100644 --- a/src/config.rs +++ b/src/config.rs @@ -697,13 +697,24 @@ impl Default for Playground { } /// Configuration for tweaking how the HTML renderer handles code blocks. -#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(default, rename_all = "kebab-case")] pub struct Code { + /// Enable or disable the default line hiding with '#' for rust. Default: `true`. + pub default_hidelines: bool, /// A prefix string to hide lines per language (one or more chars). pub hidelines: HashMap, } +impl Default for Code { + fn default() -> Code { + Code { + default_hidelines: true, + hidelines: HashMap::::default(), + } + } +} + /// Configuration of the search functionality of the HTML renderer. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(default, rename_all = "kebab-case")] diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index d0149fb523..6f2054499b 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -956,7 +956,7 @@ fn hide_lines(html: &str, code_config: &Code) -> String { let classes = &caps[2]; let code = &caps[3]; - if classes.contains("language-rust") { + if classes.contains("language-rust") && code_config.default_hidelines { format!( "{}", classes, @@ -1283,6 +1283,38 @@ mod tests { map.insert("python".to_string(), "~".to_string()); map }, + default_hidelines: true, + }, + ); + assert_eq!(&*got, *should_be); + } + } + + #[test] + fn no_default_hide_lines() { + let inputs = [ + ( + "
\n# #![allow(unused)]\n#fn main() {\nx()\n#}
", + "
\n# #![allow(unused)]\n#fn main() {\nx()\n#}
",), + ( + "
let s = \"foo\n # bar\n\";
", + "
let s = \"foo\n # bar\n\";
",), + ( + "
let s = \"foo\n ## bar\n\";
", + "
let s = \"foo\n ## bar\n\";
",), + ( + "
let s = \"foo\n # bar\n#\n\";
", + "
let s = \"foo\n # bar\n#\n\";
",), + ( + "let s = \"foo\n # bar\n\";", + "let s = \"foo\n # bar\n\";",), + ]; + for (src, should_be) in &inputs { + let got = hide_lines( + src, + &Code { + hidelines: HashMap::::default(), + default_hidelines: false, }, ); assert_eq!(&*got, *should_be);