Rollup merge of #102118 - notriddle:notriddle/line-numbers, r=GuillaumeGomez
rustdoc: clean up line numbers on code examples
* First commit switches from `display: inline-flex; width: 100%` to `display: flex`.
`display: inline-flex` was used as part of e961d397ca, the original commit that added these line numbers. Does anyone know why it was done this way?
* Second commit makes it so that toggling this checkbox will update the page in real time, just like changing themes does.
Preview: https://notriddle.com/notriddle-rustdoc-test/line-numbers/std/vec/struct.Vec.html
This commit is contained in:
commit
ecbc00fa9e
5 changed files with 56 additions and 17 deletions
|
|
@ -577,13 +577,9 @@ h2.location a {
|
|||
}
|
||||
|
||||
.rustdoc .example-wrap {
|
||||
display: inline-flex;
|
||||
display: flex;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.example-wrap {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.example-wrap > pre.line-number {
|
||||
|
|
|
|||
|
|
@ -697,20 +697,39 @@ function loadCss(cssFileName) {
|
|||
}
|
||||
}());
|
||||
|
||||
window.rustdoc_add_line_numbers_to_examples = () => {
|
||||
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
|
||||
const parent = x.parentNode;
|
||||
const line_numbers = parent.querySelectorAll(".line-number");
|
||||
if (line_numbers.length > 0) {
|
||||
return;
|
||||
}
|
||||
const count = x.textContent.split("\n").length;
|
||||
const elems = [];
|
||||
for (let i = 0; i < count; ++i) {
|
||||
elems.push(i + 1);
|
||||
}
|
||||
const node = document.createElement("pre");
|
||||
addClass(node, "line-number");
|
||||
node.innerHTML = elems.join("\n");
|
||||
parent.insertBefore(node, x);
|
||||
});
|
||||
};
|
||||
|
||||
window.rustdoc_remove_line_numbers_from_examples = () => {
|
||||
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
|
||||
const parent = x.parentNode;
|
||||
const line_numbers = parent.querySelectorAll(".line-number");
|
||||
for (const node of line_numbers) {
|
||||
parent.removeChild(node);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
(function() {
|
||||
// To avoid checking on "rustdoc-line-numbers" value on every loop...
|
||||
if (getSettingValue("line-numbers") === "true") {
|
||||
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
|
||||
const count = x.textContent.split("\n").length;
|
||||
const elems = [];
|
||||
for (let i = 0; i < count; ++i) {
|
||||
elems.push(i + 1);
|
||||
}
|
||||
const node = document.createElement("pre");
|
||||
addClass(node, "line-number");
|
||||
node.innerHTML = elems.join("\n");
|
||||
x.parentNode.insertBefore(node, x);
|
||||
});
|
||||
window.rustdoc_add_line_numbers_to_examples();
|
||||
}
|
||||
}());
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,13 @@
|
|||
updateSystemTheme();
|
||||
updateLightAndDark();
|
||||
break;
|
||||
case "line-numbers":
|
||||
if (value === true) {
|
||||
window.rustdoc_add_line_numbers_to_examples();
|
||||
} else {
|
||||
window.rustdoc_remove_line_numbers_from_examples();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue