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 lines = s.lines().count();
|
||||||
let mut line_numbers = Buffer::empty_from(buf);
|
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\">");
|
line_numbers.write_str("<pre class=\"line-numbers\">");
|
||||||
match source_context {
|
match source_context {
|
||||||
SourceContext::Standalone => {
|
SourceContext::Standalone => {
|
||||||
for line in 1..=lines {
|
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 } => {
|
SourceContext::Embedded { offset } => {
|
||||||
for line in 1..=lines {
|
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;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.line-numbers {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
.rustdoc:not(.source) .example-wrap > pre:not(.line-number) {
|
.rustdoc:not(.source) .example-wrap > pre:not(.line-number) {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user