@@ -164,7 +164,8 @@ fn write_pending_elems(
164164/// * If two `Class` have the same variant, then they can be merged.
165165/// * If the other `Class` is unclassified and only contains white characters (backline,
166166/// 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).
168169fn can_merge ( class1 : Option < Class > , class2 : Option < Class > , text : & str ) -> bool {
169170 match ( class1, class2) {
170171 ( Some ( c1) , Some ( c2) ) => c1. is_equal_to ( c2) ,
@@ -264,14 +265,15 @@ enum Class {
264265 DocComment ,
265266 Attribute ,
266267 KeyWord ,
267- // Keywords that do pointer/reference stuff.
268+ /// Keywords that do pointer/reference stuff.
268269 RefKeyWord ,
269270 Self_ ( Span ) ,
270271 Macro ( Span ) ,
271272 MacroNonTerminal ,
272273 String ,
273274 Number ,
274275 Bool ,
276+ /// `Ident` isn't rendered in the HTML but we still need it for the `Span` it contains.
275277 Ident ( Span ) ,
276278 Lifetime ,
277279 PreludeTy ,
@@ -320,7 +322,7 @@ impl Class {
320322 Class :: String => "string" ,
321323 Class :: Number => "number" ,
322324 Class :: Bool => "bool-val" ,
323- Class :: Ident ( _) => "ident " ,
325+ Class :: Ident ( _) => "" ,
324326 Class :: Lifetime => "lifetime" ,
325327 Class :: PreludeTy => "prelude-ty" ,
326328 Class :: PreludeVal => "prelude-val" ,
@@ -920,7 +922,7 @@ fn string_without_closing_tag<T: Display>(
920922 path
921923 } ) ;
922924 }
923- // We don't want to generate links on empty text.
925+
924926 if let Some ( href_context) = href_context {
925927 if let Some ( href) =
926928 href_context. context . shared . span_correspondance_map . get ( & def_span) . and_then ( |href| {
@@ -954,7 +956,12 @@ fn string_without_closing_tag<T: Display>(
954956 // again.
955957 write ! ( out, "<a href=\" {}\" >{}" , href, text_s) ;
956958 } 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+ }
958965 }
959966 return Some ( "</a>" ) ;
960967 }
@@ -963,8 +970,14 @@ fn string_without_closing_tag<T: Display>(
963970 write ! ( out, "{}" , text_s) ;
964971 return None ;
965972 }
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+ }
968981}
969982
970983#[ cfg( test) ]
0 commit comments