Skip to content

Commit 87eda78

Browse files
Generate line numbers for non-rust code examples as well
1 parent bfd74f0 commit 87eda78

File tree

1 file changed

+9
-7
lines changed
  • src/librustdoc/html/static/js

1 file changed

+9
-7
lines changed

Diff for: src/librustdoc/html/static/js/main.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,13 @@ function preLoadCss(cssUrl) {
986986
}());
987987

988988
window.rustdoc_add_line_numbers_to_examples = () => {
989-
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
989+
if (document.querySelector(".rustdoc.src")) {
990+
// We are in the source code page, nothing to be done here!
991+
return;
992+
}
993+
onEachLazy(document.querySelectorAll(
994+
":not(.scraped-example) > .example-wrap > pre:not(.example-line-numbers)",
995+
), x => {
990996
const parent = x.parentNode;
991997
const line_numbers = parent.querySelectorAll(".example-line-numbers");
992998
if (line_numbers.length > 0) {
@@ -1005,12 +1011,8 @@ function preLoadCss(cssUrl) {
10051011
};
10061012

10071013
window.rustdoc_remove_line_numbers_from_examples = () => {
1008-
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
1009-
const parent = x.parentNode;
1010-
const line_numbers = parent.querySelectorAll(".example-line-numbers");
1011-
for (const node of line_numbers) {
1012-
parent.removeChild(node);
1013-
}
1014+
onEachLazy(document.querySelectorAll(".example-wrap > .example-line-numbers"), x => {
1015+
x.parentNode.removeChild(x);
10141016
});
10151017
};
10161018

0 commit comments

Comments
 (0)