File tree 1 file changed +11
-2
lines changed
src/renderer/html_handlebars
1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -294,14 +294,23 @@ fn fix_code_blocks(html: String) -> String {
294
294
}
295
295
296
296
fn add_playpen_pre ( html : String ) -> String {
297
- let regex = Regex :: new ( r##"((?s)<code[^>]?class="([^"]+)".*?>.*?</code>)"## ) . unwrap ( ) ;
297
+ let regex = Regex :: new ( r##"((?s)<code[^>]?class="([^"]+)".*?>( .*?) </code>)"## ) . unwrap ( ) ;
298
298
regex. replace_all ( & html, |caps : & Captures | {
299
299
let text = & caps[ 1 ] ;
300
300
let classes = & caps[ 2 ] ;
301
+ let code = & caps[ 3 ] ;
301
302
302
303
if classes. contains ( "language-rust" ) && !classes. contains ( "ignore" ) {
303
304
// wrap the contents in an external pre block
304
- format ! ( "<pre class=\" playpen\" >{}</pre>" , text)
305
+
306
+ if text. contains ( "fn main" ) {
307
+ format ! ( "<pre class=\" playpen\" >{}</pre>" , text)
308
+ } else {
309
+ // we need to inject our own main
310
+ format ! ( "<pre class=\" playpen\" ><code class=\" {}\" >#fn main() {{
311
+ {}
312
+ #}}</code></pre>" , classes, code)
313
+ }
305
314
} else {
306
315
// not language-rust, so no-op
307
316
format ! ( "{}" , text)
You can’t perform that action at this time.
0 commit comments