diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index de7c5125..b184094e 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -652,26 +652,28 @@ lazy_static! { } fn hide_lines(content: &str) -> String { - let mut prev_line_hidden = false; let mut result = String::with_capacity(content.len()); for line in content.lines() { if let Some(caps) = BORING_LINES_REGEX.captures(line) { - if !prev_line_hidden && &caps[2] != "#" { - result += ""; - prev_line_hidden = true; - } - result += &caps[1]; - if &caps[2] != " " { + if &caps[2] == "#" { + result += &caps[1]; result += &caps[2]; - } - result += &caps[3]; - } else { - if prev_line_hidden { + result += &caps[3]; + result += "\n"; + continue; + } else if &caps[2] != "!" && &caps[2] != "[" { + result += ""; + result += &caps[1]; + if &caps[2] != " " { + result += &caps[2]; + } + result += &caps[3]; + result += "\n"; result += ""; - prev_line_hidden = false; + continue; } - result += line; } + result += line; result += "\n"; } result @@ -749,7 +751,7 @@ mod tests { fn add_playpen() { let inputs = [ ("x()", - "
\n#![allow(unused_variables)]\nfn main() {\nx()\n}\n
"), + "
\n#![allow(unused_variables)]\nfn main() {\nx()\n}\n
"), ("fn main() {}", "
fn main() {}\n
"), ("let s = \"foo\n # bar\n\";", @@ -757,9 +759,11 @@ mod tests { ("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\n\";\n
"), - ("let s = \"foo\n # bar\n#\n\";", - "let s = \"foo\n bar\n\n\";\n"), + "
let s = \"foo\n bar\n\n\";\n
"), + ("let s = \"foo\n # bar\n\";", + "let s = \"foo\n bar\n\";\n"), + ("#![no_std]\nlet s = \"foo\";\n #[some_attr]", + "
#![no_std]\nlet s = \"foo\";\n #[some_attr]\n
"), ]; for (src, should_be) in &inputs { let got = add_playpen_pre(