diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs
index 124c8968..65ec2d43 100644
--- a/src/renderer/html_handlebars/hbs_renderer.rs
+++ b/src/renderer/html_handlebars/hbs_renderer.rs
@@ -294,14 +294,23 @@ fn fix_code_blocks(html: String) -> String {
}
fn add_playpen_pre(html: String) -> String {
- let regex = Regex::new(r##"((?s)]?class="([^"]+)".*?>.*?
)"##).unwrap();
+ let regex = Regex::new(r##"((?s)]?class="([^"]+)".*?>(.*?)
)"##).unwrap();
regex.replace_all(&html, |caps: &Captures| {
let text = &caps[1];
let classes = &caps[2];
+ let code = &caps[3];
if classes.contains("language-rust") && !classes.contains("ignore") {
// wrap the contents in an external pre block
- format!("
{}", text) + + if text.contains("fn main") { + format!("
{}", text) + } else { + // we need to inject our own main + format!("
#fn main() {{
+{}
+#}}
", classes, code)
+ }
} else {
// not language-rust, so no-op
format!("{}", text)