mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 09:14:20 +00:00
Rollup merge of #100409 - jsha:highlight-lighter, r=GuillaumeGomez
rustdoc: don't generate DOM element for operator In our source page highlighting, we were generating `<span class="op">` tags for all "operators", including e.g. `<` `>` around generic parameters, `*`, `&`. This contributed significantly to DOM size, but we don't actually style `.op` except in the ayu theme. Remove the styles for `.op` in ayu, and stop generating the `<span>`s. This reduces DOM size of an example page[1] from 265,938 HTML elements to 242,165 elements, a 9% reduction. r? ``@GuillaumeGomez`` Demo: (warning - slow!) https://rustdoc.crud.net/jsha/highlight-lighter/src/core/up/up/stdarch/crates/core_arch/src/x86/avx512f.rs.html [1]: https://doc.rust-lang.org/nightly/src/core/up/up/stdarch/crates/core_arch/src/x86/avx512f.rs.html
This commit is contained in:
commit
03560346c4
@ -163,7 +163,6 @@ enum Class {
|
|||||||
// Keywords that do pointer/reference stuff.
|
// Keywords that do pointer/reference stuff.
|
||||||
RefKeyWord,
|
RefKeyWord,
|
||||||
Self_(Span),
|
Self_(Span),
|
||||||
Op,
|
|
||||||
Macro(Span),
|
Macro(Span),
|
||||||
MacroNonTerminal,
|
MacroNonTerminal,
|
||||||
String,
|
String,
|
||||||
@ -187,7 +186,6 @@ impl Class {
|
|||||||
Class::KeyWord => "kw",
|
Class::KeyWord => "kw",
|
||||||
Class::RefKeyWord => "kw-2",
|
Class::RefKeyWord => "kw-2",
|
||||||
Class::Self_(_) => "self",
|
Class::Self_(_) => "self",
|
||||||
Class::Op => "op",
|
|
||||||
Class::Macro(_) => "macro",
|
Class::Macro(_) => "macro",
|
||||||
Class::MacroNonTerminal => "macro-nonterminal",
|
Class::MacroNonTerminal => "macro-nonterminal",
|
||||||
Class::String => "string",
|
Class::String => "string",
|
||||||
@ -212,7 +210,6 @@ impl Class {
|
|||||||
| Self::Attribute
|
| Self::Attribute
|
||||||
| Self::KeyWord
|
| Self::KeyWord
|
||||||
| Self::RefKeyWord
|
| Self::RefKeyWord
|
||||||
| Self::Op
|
|
||||||
| Self::MacroNonTerminal
|
| Self::MacroNonTerminal
|
||||||
| Self::String
|
| Self::String
|
||||||
| Self::Number
|
| Self::Number
|
||||||
@ -516,7 +513,7 @@ impl<'a> Classifier<'a> {
|
|||||||
// or a reference or pointer type. Unless, of course, it looks like
|
// or a reference or pointer type. Unless, of course, it looks like
|
||||||
// a logical and or a multiplication operator: `&&` or `* `.
|
// a logical and or a multiplication operator: `&&` or `* `.
|
||||||
TokenKind::Star => match self.tokens.peek() {
|
TokenKind::Star => match self.tokens.peek() {
|
||||||
Some((TokenKind::Whitespace, _)) => Class::Op,
|
Some((TokenKind::Whitespace, _)) => return no_highlight(sink),
|
||||||
Some((TokenKind::Ident, "mut")) => {
|
Some((TokenKind::Ident, "mut")) => {
|
||||||
self.next();
|
self.next();
|
||||||
sink(Highlight::Token { text: "*mut", class: Some(Class::RefKeyWord) });
|
sink(Highlight::Token { text: "*mut", class: Some(Class::RefKeyWord) });
|
||||||
@ -532,15 +529,15 @@ impl<'a> Classifier<'a> {
|
|||||||
TokenKind::And => match self.tokens.peek() {
|
TokenKind::And => match self.tokens.peek() {
|
||||||
Some((TokenKind::And, _)) => {
|
Some((TokenKind::And, _)) => {
|
||||||
self.next();
|
self.next();
|
||||||
sink(Highlight::Token { text: "&&", class: Some(Class::Op) });
|
sink(Highlight::Token { text: "&&", class: None });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Some((TokenKind::Eq, _)) => {
|
Some((TokenKind::Eq, _)) => {
|
||||||
self.next();
|
self.next();
|
||||||
sink(Highlight::Token { text: "&=", class: Some(Class::Op) });
|
sink(Highlight::Token { text: "&=", class: None });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Some((TokenKind::Whitespace, _)) => Class::Op,
|
Some((TokenKind::Whitespace, _)) => return no_highlight(sink),
|
||||||
Some((TokenKind::Ident, "mut")) => {
|
Some((TokenKind::Ident, "mut")) => {
|
||||||
self.next();
|
self.next();
|
||||||
sink(Highlight::Token { text: "&mut", class: Some(Class::RefKeyWord) });
|
sink(Highlight::Token { text: "&mut", class: Some(Class::RefKeyWord) });
|
||||||
@ -553,7 +550,7 @@ impl<'a> Classifier<'a> {
|
|||||||
TokenKind::Eq => match lookahead {
|
TokenKind::Eq => match lookahead {
|
||||||
Some(TokenKind::Eq) => {
|
Some(TokenKind::Eq) => {
|
||||||
self.next();
|
self.next();
|
||||||
sink(Highlight::Token { text: "==", class: Some(Class::Op) });
|
sink(Highlight::Token { text: "==", class: None });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Some(TokenKind::Gt) => {
|
Some(TokenKind::Gt) => {
|
||||||
@ -561,7 +558,7 @@ impl<'a> Classifier<'a> {
|
|||||||
sink(Highlight::Token { text: "=>", class: None });
|
sink(Highlight::Token { text: "=>", class: None });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_ => Class::Op,
|
_ => return no_highlight(sink),
|
||||||
},
|
},
|
||||||
TokenKind::Minus if lookahead == Some(TokenKind::Gt) => {
|
TokenKind::Minus if lookahead == Some(TokenKind::Gt) => {
|
||||||
self.next();
|
self.next();
|
||||||
@ -578,7 +575,7 @@ impl<'a> Classifier<'a> {
|
|||||||
| TokenKind::Percent
|
| TokenKind::Percent
|
||||||
| TokenKind::Bang
|
| TokenKind::Bang
|
||||||
| TokenKind::Lt
|
| TokenKind::Lt
|
||||||
| TokenKind::Gt => Class::Op,
|
| TokenKind::Gt => return no_highlight(sink),
|
||||||
|
|
||||||
// Miscellaneous, no highlighting.
|
// Miscellaneous, no highlighting.
|
||||||
TokenKind::Dot
|
TokenKind::Dot
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
<span class="example"><span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">1</span>;</span>
|
<span class="example"><span class="kw">let</span> <span class="ident">x</span> = <span class="number">1</span>;</span>
|
||||||
<span class="kw">let</span> <span class="ident">y</span> <span class="op">=</span> <span class="number">2</span>;
|
<span class="kw">let</span> <span class="ident">y</span> = <span class="number">2</span>;
|
@ -1,4 +1,4 @@
|
|||||||
<span class="kw">use</span> <span class="ident"><span class="kw">crate</span>::a::foo</span>;
|
<span class="kw">use</span> <span class="ident"><span class="kw">crate</span>::a::foo</span>;
|
||||||
<span class="kw">use</span> <span class="ident"><span class="self">self</span>::whatever</span>;
|
<span class="kw">use</span> <span class="ident"><span class="self">self</span>::whatever</span>;
|
||||||
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="ident"><span class="kw">super</span>::b::foo</span>;
|
<span class="kw">let</span> <span class="ident">x</span> = <span class="ident"><span class="kw">super</span>::b::foo</span>;
|
||||||
<span class="kw">let</span> <span class="ident">y</span> <span class="op">=</span> <span class="ident"><span class="self">Self</span>::whatever</span>;
|
<span class="kw">let</span> <span class="ident">y</span> = <span class="ident"><span class="self">Self</span>::whatever</span>;
|
@ -8,23 +8,23 @@
|
|||||||
.lifetime { color: #B76514; }
|
.lifetime { color: #B76514; }
|
||||||
.question-mark { color: #ff9011; }
|
.question-mark { color: #ff9011; }
|
||||||
</style>
|
</style>
|
||||||
<pre><code><span class="attribute">#![<span class="ident">crate_type</span> <span class="op">=</span> <span class="string">"lib"</span>]</span>
|
<pre><code><span class="attribute">#![<span class="ident">crate_type</span> = <span class="string">"lib"</span>]</span>
|
||||||
|
|
||||||
<span class="kw">use</span> <span class="ident">std::path</span>::{<span class="ident">Path</span>, <span class="ident">PathBuf</span>};
|
<span class="kw">use</span> <span class="ident">std::path</span>::{<span class="ident">Path</span>, <span class="ident">PathBuf</span>};
|
||||||
|
|
||||||
<span class="attribute">#[<span class="ident">cfg</span>(<span class="ident">target_os</span> <span class="op">=</span> <span class="string">"linux"</span>)]</span>
|
<span class="attribute">#[<span class="ident">cfg</span>(<span class="ident">target_os</span> = <span class="string">"linux"</span>)]</span>
|
||||||
<span class="kw">fn</span> <span class="ident">main</span>() -> () {
|
<span class="kw">fn</span> <span class="ident">main</span>() -> () {
|
||||||
<span class="kw">let</span> <span class="ident">foo</span> <span class="op">=</span> <span class="bool-val">true</span> <span class="op">&&</span> <span class="bool-val">false</span> <span class="op">|</span><span class="op">|</span> <span class="bool-val">true</span>;
|
<span class="kw">let</span> <span class="ident">foo</span> = <span class="bool-val">true</span> && <span class="bool-val">false</span> || <span class="bool-val">true</span>;
|
||||||
<span class="kw">let</span> <span class="kw">_</span>: <span class="kw-2">*const</span> () <span class="op">=</span> <span class="number">0</span>;
|
<span class="kw">let</span> <span class="kw">_</span>: <span class="kw-2">*const</span> () = <span class="number">0</span>;
|
||||||
<span class="kw">let</span> <span class="kw">_</span> <span class="op">=</span> <span class="kw-2">&</span><span class="ident">foo</span>;
|
<span class="kw">let</span> <span class="kw">_</span> = <span class="kw-2">&</span><span class="ident">foo</span>;
|
||||||
<span class="kw">let</span> <span class="kw">_</span> <span class="op">=</span> <span class="op">&&</span><span class="ident">foo</span>;
|
<span class="kw">let</span> <span class="kw">_</span> = &&<span class="ident">foo</span>;
|
||||||
<span class="kw">let</span> <span class="kw">_</span> <span class="op">=</span> <span class="kw-2">*</span><span class="ident">foo</span>;
|
<span class="kw">let</span> <span class="kw">_</span> = <span class="kw-2">*</span><span class="ident">foo</span>;
|
||||||
<span class="macro">mac!</span>(<span class="ident">foo</span>, <span class="kw-2">&mut</span> <span class="ident">bar</span>);
|
<span class="macro">mac!</span>(<span class="ident">foo</span>, <span class="kw-2">&mut</span> <span class="ident">bar</span>);
|
||||||
<span class="macro">assert!</span>(<span class="self">self</span>.<span class="ident">length</span> <span class="op"><</span> <span class="ident">N</span> <span class="op">&&</span> <span class="ident">index</span> <span class="op"><</span><span class="op">=</span> <span class="self">self</span>.<span class="ident">length</span>);
|
<span class="macro">assert!</span>(<span class="self">self</span>.<span class="ident">length</span> < <span class="ident">N</span> && <span class="ident">index</span> <= <span class="self">self</span>.<span class="ident">length</span>);
|
||||||
<span class="ident">::std::env::var</span>(<span class="string">"gateau"</span>).<span class="ident">is_ok</span>();
|
<span class="ident">::std::env::var</span>(<span class="string">"gateau"</span>).<span class="ident">is_ok</span>();
|
||||||
<span class="attribute">#[<span class="ident">rustfmt::skip</span>]</span>
|
<span class="attribute">#[<span class="ident">rustfmt::skip</span>]</span>
|
||||||
<span class="kw">let</span> <span class="ident">s</span>:<span class="ident">std::path::PathBuf</span> <span class="op">=</span> <span class="ident">std::path::PathBuf::new</span>();
|
<span class="kw">let</span> <span class="ident">s</span>:<span class="ident">std::path::PathBuf</span> = <span class="ident">std::path::PathBuf::new</span>();
|
||||||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">String::new</span>();
|
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">s</span> = <span class="ident">String::new</span>();
|
||||||
|
|
||||||
<span class="kw">match</span> <span class="kw-2">&</span><span class="ident">s</span> {
|
<span class="kw">match</span> <span class="kw-2">&</span><span class="ident">s</span> {
|
||||||
<span class="kw-2">ref</span> <span class="kw-2">mut</span> <span class="ident">x</span> => {}
|
<span class="kw-2">ref</span> <span class="kw-2">mut</span> <span class="ident">x</span> => {}
|
||||||
|
@ -4,5 +4,5 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
<span class="kw">fn</span> <span class="ident">main</span>() {
|
<span class="kw">fn</span> <span class="ident">main</span>() {
|
||||||
<span class="kw">let</span> <span class="ident">union</span> <span class="op">=</span> <span class="number">0</span>;
|
<span class="kw">let</span> <span class="ident">union</span> = <span class="number">0</span>;
|
||||||
}
|
}
|
||||||
|
@ -238,7 +238,7 @@ details.rustdoc-toggle > summary::before {
|
|||||||
pre.rust .number, pre.rust .string { color: #b8cc52; }
|
pre.rust .number, pre.rust .string { color: #b8cc52; }
|
||||||
pre.rust .kw, pre.rust .kw-2, pre.rust .prelude-ty,
|
pre.rust .kw, pre.rust .kw-2, pre.rust .prelude-ty,
|
||||||
pre.rust .bool-val, pre.rust .prelude-val,
|
pre.rust .bool-val, pre.rust .prelude-val,
|
||||||
pre.rust .op, pre.rust .lifetime { color: #ff7733; }
|
pre.rust .lifetime { color: #ff7733; }
|
||||||
pre.rust .macro, pre.rust .macro-nonterminal { color: #a37acc; }
|
pre.rust .macro, pre.rust .macro-nonterminal { color: #a37acc; }
|
||||||
pre.rust .question-mark {
|
pre.rust .question-mark {
|
||||||
color: #ff9011;
|
color: #ff9011;
|
||||||
@ -250,7 +250,7 @@ pre.rust .self {
|
|||||||
pre.rust .attribute {
|
pre.rust .attribute {
|
||||||
color: #e6e1cf;
|
color: #e6e1cf;
|
||||||
}
|
}
|
||||||
pre.rust .attribute .ident, pre.rust .attribute .op {
|
pre.rust .attribute .ident {
|
||||||
color: #e6e1cf;
|
color: #e6e1cf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,16 +6,13 @@
|
|||||||
// @has 'foo/macro.todo.html'
|
// @has 'foo/macro.todo.html'
|
||||||
// @has - '//span[@class="macro"]' 'macro_rules!'
|
// @has - '//span[@class="macro"]' 'macro_rules!'
|
||||||
// @has - '//span[@class="ident"]' 'todo'
|
// @has - '//span[@class="ident"]' 'todo'
|
||||||
// Note: the only op is the `+`
|
|
||||||
// @count - '//pre[@class="rust macro"]//span[@class="op"]' 1
|
|
||||||
|
|
||||||
// @has - '{ () => { ... }; ($('
|
// @has - '{ () => { ... }; ($('
|
||||||
// @has - '//span[@class="macro-nonterminal"]' '$'
|
// @has - '//span[@class="macro-nonterminal"]' '$'
|
||||||
// @has - '//span[@class="macro-nonterminal"]' 'arg'
|
// @has - '//span[@class="macro-nonterminal"]' 'arg'
|
||||||
// @has - ':'
|
// @has - ':'
|
||||||
// @has - '//span[@class="ident"]' 'tt'
|
// @has - '//span[@class="ident"]' 'tt'
|
||||||
// @has - '),'
|
// @has - ')+'
|
||||||
// @has - '//span[@class="op"]' '+'
|
|
||||||
// @has - ') => { ... }; }'
|
// @has - ') => { ... }; }'
|
||||||
pub use std::todo;
|
pub use std::todo;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user