@@ -207,6 +207,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
207207 let should_panic;
208208 let ignore;
209209 let edition;
210+ let added_classes;
210211 if let Some ( Event :: Start ( Tag :: CodeBlock ( kind) ) ) = event {
211212 let parse_result = match kind {
212213 CodeBlockKind :: Fenced ( ref lang) => {
@@ -221,6 +222,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
221222 should_panic = parse_result. should_panic ;
222223 ignore = parse_result. ignore ;
223224 edition = parse_result. edition ;
225+ added_classes = parse_result. added_classes ;
224226 } else {
225227 return event;
226228 }
@@ -289,33 +291,42 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
289291 ) )
290292 } ) ;
291293
292- let tooltip = if ignore != Ignore :: None {
293- Some ( ( None , "ignore" ) )
294+ let ( tooltip, special_class ) = if ignore != Ignore :: None {
295+ ( Some ( ( None , "ignore" ) ) , " ignore" )
294296 } else if compile_fail {
295- Some ( ( None , "compile_fail" ) )
297+ ( Some ( ( None , "compile_fail" ) ) , " compile_fail" )
296298 } else if should_panic {
297- Some ( ( None , "should_panic" ) )
299+ ( Some ( ( None , "should_panic" ) ) , " should_panic" )
298300 } else if explicit_edition {
299- Some ( ( Some ( edition) , "edition" ) )
301+ ( Some ( ( Some ( edition) , "edition" ) ) , " edition" )
300302 } else {
301- None
303+ ( None , "" )
302304 } ;
303305
304306 // insert newline to clearly separate it from the
305307 // previous block so we can shorten the html output
306308 let mut s = Buffer :: new ( ) ;
307309 s. push_str ( "\n " ) ;
308- highlight:: render_with_highlighting (
309- & text,
310- & mut s,
311- Some ( & format ! (
312- "rust-example-rendered{}" ,
313- if let Some ( ( _, class) ) = tooltip { format!( " {}" , class) } else { String :: new( ) }
314- ) ) ,
315- playground_button. as_deref ( ) ,
316- tooltip,
317- edition,
318- ) ;
310+
311+ if added_classes. is_empty ( ) {
312+ highlight:: render_with_highlighting (
313+ & text,
314+ & mut s,
315+ Some ( & format ! ( "rust-example-rendered{}" , special_class) ) ,
316+ playground_button. as_deref ( ) ,
317+ tooltip,
318+ edition,
319+ ) ;
320+ } else {
321+ let classes = if special_class. is_empty ( ) {
322+ added_classes. join ( " " )
323+ } else {
324+ format ! ( "{} {}" , special_class. trim( ) , added_classes. join( " " ) )
325+ } ;
326+
327+ highlight:: render_with_added_classes ( & text, & mut s, classes, tooltip) ;
328+ }
329+
319330 Some ( Event :: Html ( s. into_inner ( ) . into ( ) ) )
320331 }
321332}
@@ -744,6 +755,7 @@ crate struct LangString {
744755 crate error_codes : Vec < String > ,
745756 crate allow_fail : bool ,
746757 crate edition : Option < Edition > ,
758+ crate added_classes : Vec < String > ,
747759}
748760
749761#[ derive( Eq , PartialEq , Clone , Debug ) ]
@@ -766,6 +778,7 @@ impl Default for LangString {
766778 error_codes : Vec :: new ( ) ,
767779 allow_fail : false ,
768780 edition : None ,
781+ added_classes : Vec :: new ( ) ,
769782 }
770783 }
771784}
@@ -775,7 +788,7 @@ impl LangString {
775788 string : & str ,
776789 allow_error_code_check : ErrorCodes ,
777790 enable_per_target_ignores : bool ,
778- ) -> LangString {
791+ ) -> Self {
779792 Self :: parse ( string, allow_error_code_check, enable_per_target_ignores, None )
780793 }
781794
@@ -809,7 +822,7 @@ impl LangString {
809822 allow_error_code_check : ErrorCodes ,
810823 enable_per_target_ignores : bool ,
811824 extra : Option < & ExtraInfo < ' _ > > ,
812- ) -> LangString {
825+ ) -> Self {
813826 let allow_error_code_check = allow_error_code_check. as_bool ( ) ;
814827 let mut seen_rust_tags = false ;
815828 let mut seen_other_tags = false ;
@@ -868,6 +881,14 @@ impl LangString {
868881 seen_other_tags = true ;
869882 }
870883 }
884+ x if x. starts_with ( "class:" ) => {
885+ let class = x. trim_start_matches ( "class:" ) ;
886+ if class. is_empty ( ) {
887+ seen_other_tags = true ;
888+ } else {
889+ data. added_classes . push ( class. to_owned ( ) ) ;
890+ }
891+ }
871892 x if extra. is_some ( ) => {
872893 let s = x. to_lowercase ( ) ;
873894 match if s == "compile-fail" || s == "compile_fail" || s == "compilefail" {
0 commit comments