Remove unneeded whitespace generation and use CSS instead instead to align line numbers to the right

This commit is contained in:
Guillaume Gomez 2022-03-07 12:04:51 +01:00
parent a64180f67f
commit e89efb8634
2 changed files with 5 additions and 8 deletions

View File

@ -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)
}
}
}

View File

@ -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;