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