Skip to content

Commit 82969e5

Browse files
Allow to go through clippy lints page without javascript
1 parent f883e28 commit 82969e5

File tree

3 files changed

+44
-26
lines changed

3 files changed

+44
-26
lines changed

util/gh-pages/index_template.html

Lines changed: 20 additions & 17 deletions
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

Lines changed: 5 additions & 6 deletions
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

Lines changed: 19 additions & 3 deletions
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)