mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-24 05:33:41 +00:00
Remove unneeded whitespace generation and use CSS instead instead to align line numbers to the right
This commit is contained in:
parent
a64180f67f
commit
e89efb8634
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user