diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs
index e5389223..3e12d39a 100644
--- a/src/renderer/html_handlebars/hbs_renderer.rs
+++ b/src/renderer/html_handlebars/hbs_renderer.rs
@@ -94,10 +94,13 @@ impl Renderer for HtmlHandlebars {
// Render the handlebars template with the data
debug!("[*]: Render template");
let rendered = try!(handlebars.render("index", &data));
-
+
// create links for headers
let rendered = build_header_links(rendered);
+ // fix code blocks
+ let rendered = fix_code_blocks(rendered);
+
// Write to file
let filename = Path::new(&ch.path).with_extension("html");
info!("[*] Creating {:?} ✓", filename.display());
@@ -143,6 +146,9 @@ impl Renderer for HtmlHandlebars {
let rendered = try!(handlebars.render("index", &data));
let rendered = build_header_links(rendered);
+ // fix code blocks
+ let rendered = fix_code_blocks(rendered);
+
try!(book.write_file(Path::new("print").with_extension("html"), &rendered.into_bytes()));
info!("[*] Creating print.html ✓");
@@ -248,3 +254,21 @@ fn build_header_links(html: String) -> String {
format!("", level=level, id=id, text=text)
}).into_owned()
}
+
+// The rust book uses annotations for rustdoc to test code snippets, like the following:
+// ```rust,should_panic
+// fn main() {
+// // Code here
+// }
+// ```
+// This function replaces all commas by spaces in the code block classes
+fn fix_code_blocks(html: String) -> String {
+ let regex = Regex::new(r##"]+)class="([^"]+)"([^>]*)>"##).unwrap();
+ regex.replace_all(&html, |caps: &Captures| {
+ let before = &caps[1];
+ let classes = &caps[2].replace(",", " ");
+ let after = &caps[3];
+
+ format!("", before=before, classes=classes, after=after)
+ }).into_owned()
+}