diff options
| author | Guillaume Gomez <guillaume.gomez@huawei.com> | 2024-09-21 15:58:35 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume.gomez@huawei.com> | 2024-09-22 00:18:44 +0200 |
| commit | 54efd132aeac8e12c6b2b734ab6f1ac3002f09fb (patch) | |
| tree | cdc353101c310fe028468be01d0b46f42dccd14e | |
| parent | 7c352665525f19d99d4564d461589f47c290ac57 (diff) | |
| download | rust-54efd132aeac8e12c6b2b734ab6f1ac3002f09fb.tar.gz rust-54efd132aeac8e12c6b2b734ab6f1ac3002f09fb.zip | |
Generate line numbers for non-rust code examples as well
| -rw-r--r-- | src/librustdoc/html/static/js/main.js | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index a0ec45b5ef3..0eba80133df 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -986,7 +986,13 @@ function preLoadCss(cssUrl) { }()); window.rustdoc_add_line_numbers_to_examples = () => { - onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => { + if (document.querySelector(".rustdoc.src")) { + // We are in the source code page, nothing to be done here! + return; + } + onEachLazy(document.querySelectorAll( + ":not(.scraped-example) > .example-wrap > pre:not(.example-line-numbers)", + ), x => { const parent = x.parentNode; const line_numbers = parent.querySelectorAll(".example-line-numbers"); if (line_numbers.length > 0) { @@ -1005,12 +1011,8 @@ function preLoadCss(cssUrl) { }; window.rustdoc_remove_line_numbers_from_examples = () => { - onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => { - const parent = x.parentNode; - const line_numbers = parent.querySelectorAll(".example-line-numbers"); - for (const node of line_numbers) { - parent.removeChild(node); - } + onEachLazy(document.querySelectorAll(".example-wrap > .example-line-numbers"), x => { + x.parentNode.removeChild(x); }); }; |
