@@ -160,10 +160,15 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'a, I> {
160
160
161
161
fn next ( & mut self ) -> Option < Self :: Item > {
162
162
let event = self . inner . next ( ) ;
163
+ let compile_fail;
164
+ let ignore;
163
165
if let Some ( Event :: Start ( Tag :: CodeBlock ( lang) ) ) = event {
164
- if !LangString :: parse ( & lang) . rust {
166
+ let parse_result = LangString :: parse ( & lang) ;
167
+ if !parse_result. rust {
165
168
return Some ( Event :: Start ( Tag :: CodeBlock ( lang) ) ) ;
166
169
}
170
+ compile_fail = parse_result. compile_fail ;
171
+ ignore = parse_result. ignore ;
167
172
} else {
168
173
return event;
169
174
}
@@ -222,11 +227,22 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'a, I> {
222
227
url, test_escaped, channel
223
228
) )
224
229
} ) ;
230
+ let tooltip = if ignore {
231
+ Some ( ( "Be careful when using this code, it's not being tested!" , "ignore" ) )
232
+ } else if compile_fail {
233
+ Some ( ( "This code doesn't compile so be extra careful!" , "compile_fail" ) )
234
+ } else {
235
+ None
236
+ } ;
225
237
s. push_str ( & highlight:: render_with_highlighting (
226
238
& text,
227
- Some ( "rust-example-rendered" ) ,
239
+ Some ( & format ! ( "rust-example-rendered{}" ,
240
+ if ignore { " ignore" }
241
+ else if compile_fail { " compile_fail" }
242
+ else { "" } ) ) ,
228
243
None ,
229
- playground_button. as_ref ( ) . map ( String :: as_str) ) ) ;
244
+ playground_button. as_ref ( ) . map ( String :: as_str) ,
245
+ tooltip) ) ;
230
246
Some ( Event :: Html ( s. into ( ) ) )
231
247
} )
232
248
}
@@ -556,12 +572,18 @@ pub fn render(w: &mut fmt::Formatter,
556
572
let origtext = str:: from_utf8 ( text) . unwrap ( ) ;
557
573
let origtext = origtext. trim_left ( ) ;
558
574
debug ! ( "docblock: ==============\n {:?}\n =======" , text) ;
575
+ let mut compile_fail = false ;
576
+ let mut ignore = false ;
577
+
559
578
let rendered = if lang. is_null ( ) || origtext. is_empty ( ) {
560
579
false
561
580
} else {
562
581
let rlang = ( * lang) . as_bytes ( ) ;
563
582
let rlang = str:: from_utf8 ( rlang) . unwrap ( ) ;
564
- if !LangString :: parse ( rlang) . rust {
583
+ let parse_result = LangString :: parse ( rlang) ;
584
+ compile_fail = parse_result. compile_fail ;
585
+ ignore = parse_result. ignore ;
586
+ if !parse_result. rust {
565
587
( my_opaque. dfltblk ) ( ob, orig_text, lang,
566
588
opaque as * const hoedown_renderer_data ,
567
589
line) ;
@@ -616,11 +638,22 @@ pub fn render(w: &mut fmt::Formatter,
616
638
url, test_escaped, channel
617
639
) )
618
640
} ) ;
641
+ let tooltip = if ignore {
642
+ Some ( ( "Be careful when using this code, it's not being tested!" , "ignore" ) )
643
+ } else if compile_fail {
644
+ Some ( ( "This code doesn't compile so be extra careful!" , "compile_fail" ) )
645
+ } else {
646
+ None
647
+ } ;
619
648
s. push_str ( & highlight:: render_with_highlighting (
620
649
& text,
621
- Some ( "rust-example-rendered" ) ,
650
+ Some ( & format ! ( "rust-example-rendered{}" ,
651
+ if ignore { " ignore" }
652
+ else if compile_fail { " compile_fail" }
653
+ else { "" } ) ) ,
622
654
None ,
623
- playground_button. as_ref ( ) . map ( String :: as_str) ) ) ;
655
+ playground_button. as_ref ( ) . map ( String :: as_str) ,
656
+ tooltip) ) ;
624
657
hoedown_buffer_put ( ob, s. as_ptr ( ) , s. len ( ) ) ;
625
658
} )
626
659
}
0 commit comments