diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:32 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:32 +0000 |
commit | 4547b622d8d29df964fa2914213088b148c498fc (patch) | |
tree | 9fc6b25f3c3add6b745be9a2400a6e96140046e9 /src/librustdoc/html/sources.rs | |
parent | Releasing progress-linux version 1.66.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-4547b622d8d29df964fa2914213088b148c498fc.tar.xz rustc-4547b622d8d29df964fa2914213088b148c498fc.zip |
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/librustdoc/html/sources.rs')
-rw-r--r-- | src/librustdoc/html/sources.rs | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index 7ab65bff3..54e296959 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -258,7 +258,7 @@ where pub(crate) enum SourceContext { Standalone, - Embedded { offset: usize }, + Embedded { offset: usize, needs_expansion: bool }, } /// Wrapper struct to render the source code of a file. This will do things like @@ -274,28 +274,37 @@ pub(crate) fn print_src( ) { let lines = s.lines().count(); let mut line_numbers = Buffer::empty_from(buf); + let extra; line_numbers.write_str("<pre class=\"src-line-numbers\">"); + let current_href = &context + .href_from_span(clean::Span::new(file_span), false) + .expect("only local crates should have sources emitted"); match source_context { SourceContext::Standalone => { + extra = None; for line in 1..=lines { - writeln!(line_numbers, "<span id=\"{0}\">{0}</span>", line) + writeln!(line_numbers, "<a href=\"#{line}\" id=\"{line}\">{line}</a>") } } - SourceContext::Embedded { offset } => { - for line in 1..=lines { - writeln!(line_numbers, "<span>{0}</span>", line + offset) + SourceContext::Embedded { offset, needs_expansion } => { + extra = if needs_expansion { + Some(r#"<button class="expand">↕</button>"#) + } else { + None + }; + for line_number in 1..=lines { + let line = line_number + offset; + writeln!(line_numbers, "<span>{line}</span>") } } } line_numbers.write_str("</pre>"); - let current_href = &context - .href_from_span(clean::Span::new(file_span), false) - .expect("only local crates should have sources emitted"); highlight::render_source_with_highlighting( s, buf, line_numbers, highlight::HrefContext { context, file_span, root_path, current_href }, decoration_info, + extra, ); } |