");
- let offset = offset.unwrap_or(0);
for i in 1..=lines {
- writeln!(line_numbers, "{0:1$}", i + offset, cols);
+ match source_context {
+ SourceContext::Standalone => {
+ writeln!(line_numbers, "{0:1$}", i, cols)
+ }
+ SourceContext::Embedded { offset } => {
+ writeln!(line_numbers, "{0:1$}", i + offset, cols)
+ }
+ }
}
line_numbers.write_str("");
highlight::render_with_highlighting(
diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index 7ebeffe85dd8..820f6a00f208 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -1978,12 +1978,16 @@ details.undocumented[open] > summary::before {
font-family: 'Fira Sans';
}
-.scraped-example:not(.expanded) .code-wrapper pre.line-numbers,
-.scraped-example:not(.expanded) .code-wrapper .example-wrap pre.rust {
+.scraped-example:not(.expanded) .code-wrapper pre.line-numbers {
overflow: hidden;
max-height: 240px;
}
+.scraped-example:not(.expanded) .code-wrapper .example-wrap pre.rust {
+ overflow-y: hidden;
+ max-height: 240px;
+}
+
.scraped-example .code-wrapper .prev {
position: absolute;
top: 0.25em;
@@ -2019,7 +2023,7 @@ details.undocumented[open] > summary::before {
.scraped-example:not(.expanded) .code-wrapper:before {
content: " ";
width: 100%;
- height: 10px;
+ height: 5px;
position: absolute;
z-index: 100;
top: 0;
@@ -2029,7 +2033,7 @@ details.undocumented[open] > summary::before {
.scraped-example:not(.expanded) .code-wrapper:after {
content: " ";
width: 100%;
- height: 10px;
+ height: 5px;
position: absolute;
z-index: 100;
bottom: 0;
diff --git a/src/librustdoc/html/static/js/scrape-examples.js b/src/librustdoc/html/static/js/scrape-examples.js
index 191ce37d6535..307843f24261 100644
--- a/src/librustdoc/html/static/js/scrape-examples.js
+++ b/src/librustdoc/html/static/js/scrape-examples.js
@@ -15,7 +15,8 @@
function updateScrapedExample(example) {
var locs = JSON.parse(example.attributes.getNamedItem("data-locs").textContent);
- var offset = parseInt(example.attributes.getNamedItem("data-offset").textContent);
+ var first_line_no = example.querySelector('.line-numbers > span:first-child');
+ var offset = parseInt(first_line_no.innerHTML) - 1;
var locIndex = 0;
var highlights = example.querySelectorAll('.highlight');
@@ -68,11 +69,8 @@
example.querySelector('.next').remove();
}
- var codeEl = example.querySelector('.rust');
- var codeOverflows = codeEl.scrollHeight > codeEl.clientHeight;
var expandButton = example.querySelector('.expand');
- if (codeOverflows) {
- // If file is larger than default height, give option to expand the viewer
+ if (expandButton) {
expandButton.addEventListener('click', function () {
if (hasClass(example, "expanded")) {
removeClass(example, "expanded");
@@ -81,10 +79,6 @@
addClass(example, "expanded");
}
});
- } else {
- // Otherwise remove expansion buttons
- addClass(example, 'expanded');
- expandButton.remove();
}
// Start with the first example in view