Skip to content

Commit 33df8a9

Browse files
Don't generate ident elements as DOM nodes
1 parent 68f327b commit 33df8a9

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

Diff for: src/librustdoc/html/highlight.rs

+20-7
Original file line numberDiff line numberDiff line change
@@ -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).
168169
fn 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)]

Diff for: src/librustdoc/html/static/css/themes/ayu.css

+1-5
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,6 @@ pre.rust .self {
250250
pre.rust .attribute {
251251
color: #e6e1cf;
252252
}
253-
pre.rust .attribute .ident {
254-
color: #e6e1cf;
255-
}
256253

257254
.example-wrap > pre.line-number {
258255
color: #5c67736e;
@@ -398,8 +395,7 @@ pre.rust .comment {}
398395
.block a.current.method,.content span.tymethod,.content a.tymethod,.block a.current.tymethod,
399396
.content .fnname {}
400397
pre.rust .kw {}
401-
pre.rust .self,pre.rust .bool-val,pre.rust .prelude-val,pre.rust .attribute,
402-
pre.rust .attribute .ident {}
398+
pre.rust .self,pre.rust .bool-val,pre.rust .prelude-val,pre.rust .attribute {}
403399
.content span.foreigntype,.content a.foreigntype,.block a.current.foreigntype {}
404400
pre.rust .doccomment {}
405401
.stab.deprecated {}

Diff for: src/librustdoc/html/static/css/themes/dark.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ pre.rust .kw { color: #ab8ac1; }
202202
pre.rust .kw-2, pre.rust .prelude-ty { color: #769acb; }
203203
pre.rust .number, pre.rust .string { color: #83a300; }
204204
pre.rust .self, pre.rust .bool-val, pre.rust .prelude-val,
205-
pre.rust .attribute, pre.rust .attribute .ident { color: #ee6868; }
205+
pre.rust .attribute { color: #ee6868; }
206206
pre.rust .macro, pre.rust .macro-nonterminal { color: #3E999F; }
207207
pre.rust .lifetime { color: #d97f26; }
208208
pre.rust .question-mark {

Diff for: src/librustdoc/html/static/css/themes/light.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pre.rust .kw { color: #8959A8; }
184184
pre.rust .kw-2, pre.rust .prelude-ty { color: #4271AE; }
185185
pre.rust .number, pre.rust .string { color: #718C00; }
186186
pre.rust .self, pre.rust .bool-val, pre.rust .prelude-val,
187-
pre.rust .attribute, pre.rust .attribute .ident { color: #C82829; }
187+
pre.rust .attribute { color: #C82829; }
188188
pre.rust .comment { color: #8E908C; }
189189
pre.rust .doccomment { color: #4D4D4C; }
190190
pre.rust .macro, pre.rust .macro-nonterminal { color: #3E999F; }

0 commit comments

Comments
 (0)