Skip to content

Commit 6a79588

Browse files
committed
Auto merge of rust-lang#13539 - GuillaumeGomez:allow-no-js, r=Alexendoo
Allow to go through clippy lints page without javascript Fixes rust-lang#13536. This is the follow-up of rust-lang/rust-clippy#13269. This PR makes it possible to expand/collapse lints (individually) without JS. To achieve this result, there are two ways: 1. Use `details` and `summary` tags. Problem with this approach is that the web browser search may open the `details` tags automatically if content matching it is inside. From a previous discussion with `@Alexendoo,` it seems to not be a desired behaviour. 2. Use a little trick where you use a `label` and a checkbox where the checkbox is in fact hidden. Then it's just a matter of CSS. r? `@Alexendoo` changelog: Allow to go through clippy lints page without JS
2 parents 47effe4 + da19d47 commit 6a79588

File tree

4 files changed

+46
-27
lines changed

4 files changed

+46
-27
lines changed

tests/compile-test.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,8 @@ struct Renderer<'a> {
396396

397397
impl Renderer<'_> {
398398
fn markdown(input: &str) -> Safe<String> {
399-
let parser = Parser::new_ext(input, Options::all());
399+
let input = clippy_config::sanitize_explanation(input);
400+
let parser = Parser::new_ext(&input, Options::all());
400401
let mut html_output = String::new();
401402
html::push_html(&mut html_output, parser);
402403
// Oh deer, what a hack :O

util/gh-pages/index_template.html

+20-17
Original file line numberDiff line numberDiff line change
@@ -143,26 +143,29 @@ <h1>Clippy Lints</h1> {# #}
143143
</div> {# #}
144144
</div>
145145
{% for lint in lints %}
146-
<article class="panel panel-default collapsed" id="{{lint.id}}"> {# #}
147-
<header class="panel-heading" onclick="expandLint('{{lint.id}}')"> {# #}
148-
<h2 class="panel-title"> {# #}
149-
<div class="panel-title-name" id="lint-{{lint.id}}"> {# #}
150-
<span>{{lint.id}}</span> {#+ #}
151-
<a href="#{{lint.id}}" class="anchor label label-default" onclick="openLint(event)">&para;</a> {#+ #}
152-
<a href="" class="anchor label label-default" onclick="copyToClipboard(event)"> {# #}
153-
&#128203; {# #}
154-
</a> {# #}
155-
</div> {# #}
146+
<article class="panel panel-default" id="{{lint.id}}"> {# #}
147+
<input id="label-{{lint.id}}" type="checkbox"> {# #}
148+
<label for="label-{{lint.id}}" onclick="highlightIfNeeded('{{lint.id}}')"> {# #}
149+
<header class="panel-heading"> {# #}
150+
<h2 class="panel-title"> {# #}
151+
<div class="panel-title-name" id="lint-{{lint.id}}"> {# #}
152+
<span>{{lint.id}}</span> {#+ #}
153+
<a href="#{{lint.id}}" class="anchor label label-default" onclick="openLint(event)">&para;</a> {#+ #}
154+
<a href="" class="anchor label label-default" onclick="copyToClipboard(event)"> {# #}
155+
&#128203; {# #}
156+
</a> {# #}
157+
</div> {# #}
156158

157-
<div class="panel-title-addons"> {# #}
158-
<span class="label label-lint-group label-default label-group-{{lint.group}}">{{lint.group}}</span> {#+ #}
159+
<div class="panel-title-addons"> {# #}
160+
<span class="label label-lint-group label-default label-group-{{lint.group}}">{{lint.group}}</span> {#+ #}
159161

160-
<span class="label label-lint-level label-lint-level-{{lint.level}}">{{lint.level}}</span> {#+ #}
162+
<span class="label label-lint-level label-lint-level-{{lint.level}}">{{lint.level}}</span> {#+ #}
161163

162-
<span class="label label-doc-folding">&plus;</span> {# #}
163-
</div> {# #}
164-
</h2> {# #}
165-
</header> {# #}
164+
<span class="label label-doc-folding"></span> {# #}
165+
</div> {# #}
166+
</h2> {# #}
167+
</header> {# #}
168+
</label> {# #}
166169

167170
<div class="list-group lint-docs"> {# #}
168171
<div class="list-group-item lint-doc-md">{{Self::markdown(lint.docs)}}</div> {# #}

util/gh-pages/script.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,17 @@ function onEachLazy(lazyArray, func) {
138138
}
139139
}
140140

141-
function highlightIfNeeded(elem) {
142-
onEachLazy(elem.querySelectorAll("pre > code.language-rust:not(.highlighted)"), el => {
141+
function highlightIfNeeded(lintId) {
142+
onEachLazy(document.querySelectorAll(`#${lintId} pre > code:not(.hljs)`), el => {
143143
hljs.highlightElement(el.parentElement)
144144
el.classList.add("highlighted");
145145
});
146146
}
147147

148148
function expandLint(lintId) {
149-
const lintElem = document.getElementById(lintId);
150-
const isCollapsed = lintElem.classList.toggle("collapsed");
151-
lintElem.querySelector(".label-doc-folding").innerText = isCollapsed ? "+" : "−";
152-
highlightIfNeeded(lintElem);
149+
const elem = document.querySelector(`#${lintId} > input[type="checkbox"]`);
150+
elem.checked = true;
151+
highlightIfNeeded(lintId);
153152
}
154153

155154
// Show details for one lint

util/gh-pages/style.css

+19-3
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,12 @@ L4.75,12h2.5l0.5393066-2.1572876 c0.2276001-0.1062012,0.4459839-0.2269287,0.649
309309
.page-header {
310310
border-color: var(--theme-popup-border);
311311
}
312-
.panel-default > .panel-heading {
312+
.panel-default .panel-heading {
313313
background: var(--theme-hover);
314314
color: var(--fg);
315315
border: 1px solid var(--theme-popup-border);
316316
}
317-
.panel-default > .panel-heading:hover {
317+
.panel-default .panel-heading:hover {
318318
filter: brightness(90%);
319319
}
320320
.list-group-item {
@@ -410,9 +410,25 @@ body {
410410
color: var(--fg);
411411
}
412412

413-
article.collapsed .lint-docs {
413+
article > label {
414+
width: 100%;
415+
margin: 0;
416+
}
417+
article > input[type="checkbox"] {
414418
display: none;
415419
}
420+
article > input[type="checkbox"] + label .label-doc-folding::before {
421+
content: "+";
422+
}
423+
article > input[type="checkbox"]:checked + label .label-doc-folding::before {
424+
content: "−";
425+
}
426+
.lint-docs {
427+
display: none;
428+
}
429+
article > input[type="checkbox"]:checked ~ .lint-docs {
430+
display: block;
431+
}
416432

417433
.github-corner svg {
418434
fill: var(--fg);

0 commit comments

Comments
 (0)