mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-21 20:23:12 +00:00
Run syntax highlighting only when needed
This commit is contained in:
parent
823c1246ab
commit
80eb9cfa14
1 changed files with 13 additions and 3 deletions
|
@ -138,6 +138,13 @@ function onEachLazy(lazyArray, func) {
|
|||
}
|
||||
}
|
||||
|
||||
function highlightIfNeeded(elem) {
|
||||
onEachLazy(elem.querySelectorAll("pre > code.language-rust:not(.highlighted)"), el => {
|
||||
hljs.highlightElement(el)
|
||||
el.classList.add("highlighted");
|
||||
});
|
||||
}
|
||||
|
||||
function expandLintId(lintId) {
|
||||
searchState.inputElem.value = lintId;
|
||||
searchState.filterLints();
|
||||
|
@ -146,7 +153,7 @@ function expandLintId(lintId) {
|
|||
const lintElem = document.getElementById(lintId);
|
||||
const isCollapsed = lintElem.classList.remove("collapsed");
|
||||
lintElem.querySelector(".label-doc-folding").innerText = "-";
|
||||
onEachLazy(lintElem.querySelectorAll("pre > code.language-rust"), el => hljs.highlightElement(el));
|
||||
highlightIfNeeded(lintElem);
|
||||
}
|
||||
|
||||
// Show details for one lint
|
||||
|
@ -160,7 +167,7 @@ function expandLint(lintId) {
|
|||
const lintElem = document.getElementById(lintId);
|
||||
const isCollapsed = lintElem.classList.toggle("collapsed");
|
||||
lintElem.querySelector(".label-doc-folding").innerText = isCollapsed ? "+" : "-";
|
||||
onEachLazy(lintElem.querySelectorAll("pre > code.language-rust"), el => hljs.highlightElement(el));
|
||||
highlightIfNeeded(lintElem);
|
||||
}
|
||||
|
||||
function copyToClipboard(event) {
|
||||
|
@ -198,7 +205,10 @@ function handleBlur(event, elementId) {
|
|||
function toggleExpansion(expand) {
|
||||
onEachLazy(
|
||||
document.querySelectorAll("article"),
|
||||
expand ? el => el.classList.remove("collapsed") : el => el.classList.add("collapsed"),
|
||||
expand ? el => {
|
||||
el.classList.remove("collapsed");
|
||||
highlightIfNeeded(el);
|
||||
} : el => el.classList.add("collapsed"),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue