@@ -160,10 +160,15 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'a, I> {
160160
161161 fn next ( & mut self ) -> Option < Self :: Item > {
162162 let event = self . inner . next ( ) ;
163+ let compile_fail;
164+ let ignore;
163165 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 {
165168 return Some ( Event :: Start ( Tag :: CodeBlock ( lang) ) ) ;
166169 }
170+ compile_fail = parse_result. compile_fail ;
171+ ignore = parse_result. ignore ;
167172 } else {
168173 return event;
169174 }
@@ -222,11 +227,22 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'a, I> {
222227 url, test_escaped, channel
223228 ) )
224229 } ) ;
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+ } ;
225237 s. push_str ( & highlight:: render_with_highlighting (
226238 & 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 { "" } ) ) ,
228243 None ,
229- playground_button. as_ref ( ) . map ( String :: as_str) ) ) ;
244+ playground_button. as_ref ( ) . map ( String :: as_str) ,
245+ tooltip) ) ;
230246 Some ( Event :: Html ( s. into ( ) ) )
231247 } )
232248 }
@@ -556,12 +572,18 @@ pub fn render(w: &mut fmt::Formatter,
556572 let origtext = str:: from_utf8 ( text) . unwrap ( ) ;
557573 let origtext = origtext. trim_left ( ) ;
558574 debug ! ( "docblock: ==============\n {:?}\n =======" , text) ;
575+ let mut compile_fail = false ;
576+ let mut ignore = false ;
577+
559578 let rendered = if lang. is_null ( ) || origtext. is_empty ( ) {
560579 false
561580 } else {
562581 let rlang = ( * lang) . as_bytes ( ) ;
563582 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 {
565587 ( my_opaque. dfltblk ) ( ob, orig_text, lang,
566588 opaque as * const hoedown_renderer_data ,
567589 line) ;
@@ -616,11 +638,22 @@ pub fn render(w: &mut fmt::Formatter,
616638 url, test_escaped, channel
617639 ) )
618640 } ) ;
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+ } ;
619648 s. push_str ( & highlight:: render_with_highlighting (
620649 & 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 { "" } ) ) ,
622654 None ,
623- playground_button. as_ref ( ) . map ( String :: as_str) ) ) ;
655+ playground_button. as_ref ( ) . map ( String :: as_str) ,
656+ tooltip) ) ;
624657 hoedown_buffer_put ( ob, s. as_ptr ( ) , s. len ( ) ) ;
625658 } )
626659 }
0 commit comments