@@ -207,6 +207,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
207
207
let should_panic;
208
208
let ignore;
209
209
let edition;
210
+ let added_classes;
210
211
if let Some ( Event :: Start ( Tag :: CodeBlock ( kind) ) ) = event {
211
212
let parse_result = match kind {
212
213
CodeBlockKind :: Fenced ( ref lang) => {
@@ -221,6 +222,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
221
222
should_panic = parse_result. should_panic ;
222
223
ignore = parse_result. ignore ;
223
224
edition = parse_result. edition ;
225
+ added_classes = parse_result. added_classes ;
224
226
} else {
225
227
return event;
226
228
}
@@ -289,33 +291,42 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
289
291
) )
290
292
} ) ;
291
293
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" )
294
296
} else if compile_fail {
295
- Some ( ( None , "compile_fail" ) )
297
+ ( Some ( ( None , "compile_fail" ) ) , " compile_fail" )
296
298
} else if should_panic {
297
- Some ( ( None , "should_panic" ) )
299
+ ( Some ( ( None , "should_panic" ) ) , " should_panic" )
298
300
} else if explicit_edition {
299
- Some ( ( Some ( edition) , "edition" ) )
301
+ ( Some ( ( Some ( edition) , "edition" ) ) , " edition" )
300
302
} else {
301
- None
303
+ ( None , "" )
302
304
} ;
303
305
304
306
// insert newline to clearly separate it from the
305
307
// previous block so we can shorten the html output
306
308
let mut s = Buffer :: new ( ) ;
307
309
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
+
319
330
Some ( Event :: Html ( s. into_inner ( ) . into ( ) ) )
320
331
}
321
332
}
@@ -744,6 +755,7 @@ crate struct LangString {
744
755
crate error_codes : Vec < String > ,
745
756
crate allow_fail : bool ,
746
757
crate edition : Option < Edition > ,
758
+ crate added_classes : Vec < String > ,
747
759
}
748
760
749
761
#[ derive( Eq , PartialEq , Clone , Debug ) ]
@@ -766,6 +778,7 @@ impl Default for LangString {
766
778
error_codes : Vec :: new ( ) ,
767
779
allow_fail : false ,
768
780
edition : None ,
781
+ added_classes : Vec :: new ( ) ,
769
782
}
770
783
}
771
784
}
@@ -775,7 +788,7 @@ impl LangString {
775
788
string : & str ,
776
789
allow_error_code_check : ErrorCodes ,
777
790
enable_per_target_ignores : bool ,
778
- ) -> LangString {
791
+ ) -> Self {
779
792
Self :: parse ( string, allow_error_code_check, enable_per_target_ignores, None )
780
793
}
781
794
@@ -809,7 +822,7 @@ impl LangString {
809
822
allow_error_code_check : ErrorCodes ,
810
823
enable_per_target_ignores : bool ,
811
824
extra : Option < & ExtraInfo < ' _ > > ,
812
- ) -> LangString {
825
+ ) -> Self {
813
826
let allow_error_code_check = allow_error_code_check. as_bool ( ) ;
814
827
let mut seen_rust_tags = false ;
815
828
let mut seen_other_tags = false ;
@@ -868,6 +881,14 @@ impl LangString {
868
881
seen_other_tags = true ;
869
882
}
870
883
}
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
+ }
871
892
x if extra. is_some ( ) => {
872
893
let s = x. to_lowercase ( ) ;
873
894
match if s == "compile-fail" || s == "compile_fail" || s == "compilefail" {
0 commit comments