mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-03 02:23:20 +00:00
Rollup merge of #94696 - GuillaumeGomez:align-line-numbers-right, r=notriddle
Remove whitespaces and use CSS to align line numbers to the right instead
Instead of generating whitespaces to create padding, we simply use the CSS rule: `text-align: right`.
Nice side-effect: it reduces the generated HTML size from **75.004** to **74.828** (MegaBytes) on the std source pages (it's not much but it's always a nice plus 😆 ).
There are no changes in the generated UI.
r? `@notriddle`
This commit is contained in:
commit
77562f2350
@ -272,22 +272,16 @@ crate fn print_src(
|
||||
) {
|
||||
let lines = s.lines().count();
|
||||
let mut line_numbers = Buffer::empty_from(buf);
|
||||
let mut cols = 0;
|
||||
let mut tmp = lines;
|
||||
while tmp > 0 {
|
||||
cols += 1;
|
||||
tmp /= 10;
|
||||
}
|
||||
line_numbers.write_str("<pre class=\"line-numbers\">");
|
||||
match source_context {
|
||||
SourceContext::Standalone => {
|
||||
for line in 1..=lines {
|
||||
writeln!(line_numbers, "<span id=\"{0}\">{0:1$}</span>", line, cols)
|
||||
writeln!(line_numbers, "<span id=\"{0}\">{0}</span>", line)
|
||||
}
|
||||
}
|
||||
SourceContext::Embedded { offset } => {
|
||||
for line in 1..=lines {
|
||||
writeln!(line_numbers, "<span>{0:1$}</span>", line + offset, cols)
|
||||
writeln!(line_numbers, "<span>{0}</span>", line + offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -541,6 +541,9 @@ h2.location a {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.line-numbers {
|
||||
text-align: right;
|
||||
}
|
||||
.rustdoc:not(.source) .example-wrap > pre:not(.line-number) {
|
||||
width: 100%;
|
||||
overflow-x: auto;
|
||||
|
@ -14,3 +14,6 @@ assert-attribute: (".line-numbers > span:nth-child(6)", {"class": "line-highligh
|
||||
assert-attribute-false: (".line-numbers > span:nth-child(7)", {"class": "line-highlighted"})
|
||||
// This is to ensure that the content is correctly align with the line numbers.
|
||||
compare-elements-position: ("//*[@id='1']", ".rust > code > span", ("y"))
|
||||
|
||||
// Assert that the line numbers text is aligned to the right.
|
||||
assert-css: (".line-numbers", {"text-align": "right"})
|
||||
|
Loading…
Reference in New Issue
Block a user