@@ -164,7 +164,8 @@ fn write_pending_elems(
164
164
/// * If two `Class` have the same variant, then they can be merged.
165
165
/// * If the other `Class` is unclassified and only contains white characters (backline,
166
166
/// whitespace, etc), it can be merged.
167
- /// * If `Class` is `Ident`, then it can be merged with all unclassified elements.
167
+ /// * `Class::Ident` is considered the same as unclassified (because it doesn't have an associated
168
+ /// CSS class).
168
169
fn can_merge ( class1 : Option < Class > , class2 : Option < Class > , text : & str ) -> bool {
169
170
match ( class1, class2) {
170
171
( Some ( c1) , Some ( c2) ) => c1. is_equal_to ( c2) ,
@@ -264,14 +265,15 @@ enum Class {
264
265
DocComment ,
265
266
Attribute ,
266
267
KeyWord ,
267
- // Keywords that do pointer/reference stuff.
268
+ /// Keywords that do pointer/reference stuff.
268
269
RefKeyWord ,
269
270
Self_ ( Span ) ,
270
271
Macro ( Span ) ,
271
272
MacroNonTerminal ,
272
273
String ,
273
274
Number ,
274
275
Bool ,
276
+ /// `Ident` isn't rendered in the HTML but we still need it for the `Span` it contains.
275
277
Ident ( Span ) ,
276
278
Lifetime ,
277
279
PreludeTy ,
@@ -320,7 +322,7 @@ impl Class {
320
322
Class :: String => "string" ,
321
323
Class :: Number => "number" ,
322
324
Class :: Bool => "bool-val" ,
323
- Class :: Ident ( _) => "ident " ,
325
+ Class :: Ident ( _) => "" ,
324
326
Class :: Lifetime => "lifetime" ,
325
327
Class :: PreludeTy => "prelude-ty" ,
326
328
Class :: PreludeVal => "prelude-val" ,
@@ -920,7 +922,7 @@ fn string_without_closing_tag<T: Display>(
920
922
path
921
923
} ) ;
922
924
}
923
- // We don't want to generate links on empty text.
925
+
924
926
if let Some ( href_context) = href_context {
925
927
if let Some ( href) =
926
928
href_context. context . shared . span_correspondance_map . get ( & def_span) . and_then ( |href| {
@@ -954,7 +956,12 @@ fn string_without_closing_tag<T: Display>(
954
956
// again.
955
957
write ! ( out, "<a href=\" {}\" >{}" , href, text_s) ;
956
958
} else {
957
- write ! ( out, "<a class=\" {}\" href=\" {}\" >{}" , klass. as_html( ) , href, text_s) ;
959
+ let klass_s = klass. as_html ( ) ;
960
+ if klass_s. is_empty ( ) {
961
+ write ! ( out, "<a href=\" {}\" >{}" , href, text_s) ;
962
+ } else {
963
+ write ! ( out, "<a class=\" {}\" href=\" {}\" >{}" , klass_s, href, text_s) ;
964
+ }
958
965
}
959
966
return Some ( "</a>" ) ;
960
967
}
@@ -963,8 +970,14 @@ fn string_without_closing_tag<T: Display>(
963
970
write ! ( out, "{}" , text_s) ;
964
971
return None ;
965
972
}
966
- write ! ( out, "<span class=\" {}\" >{}" , klass. as_html( ) , text_s) ;
967
- Some ( "</span>" )
973
+ let klass_s = klass. as_html ( ) ;
974
+ if klass_s. is_empty ( ) {
975
+ write ! ( out, "{}" , text_s) ;
976
+ Some ( "" )
977
+ } else {
978
+ write ! ( out, "<span class=\" {}\" >{}" , klass_s, text_s) ;
979
+ Some ( "</span>" )
980
+ }
968
981
}
969
982
970
983
#[ cfg( test) ]
0 commit comments