mirror of https://github.com/rust-lang/rust.git
rustdoc: avoid excessive HTML generated in example sources
This commit is contained in:
parent
ba4ae13528
commit
cb3a04b6ef
|
@ -2899,11 +2899,7 @@ fn render_call_locations(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Ite
|
|||
cx,
|
||||
&cx.root_path(),
|
||||
highlight::DecorationInfo(decoration_info),
|
||||
sources::SourceContext::Embedded {
|
||||
url: &call_data.url,
|
||||
offset: line_min,
|
||||
needs_expansion,
|
||||
},
|
||||
sources::SourceContext::Embedded { offset: line_min, needs_expansion },
|
||||
);
|
||||
write!(w, "</div></div>");
|
||||
|
||||
|
|
|
@ -256,9 +256,9 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) enum SourceContext<'a> {
|
||||
pub(crate) enum SourceContext {
|
||||
Standalone,
|
||||
Embedded { url: &'a str, offset: usize, needs_expansion: bool },
|
||||
Embedded { offset: usize, needs_expansion: bool },
|
||||
}
|
||||
|
||||
/// Wrapper struct to render the source code of a file. This will do things like
|
||||
|
@ -270,7 +270,7 @@ pub(crate) fn print_src(
|
|||
context: &Context<'_>,
|
||||
root_path: &str,
|
||||
decoration_info: highlight::DecorationInfo,
|
||||
source_context: SourceContext<'_>,
|
||||
source_context: SourceContext,
|
||||
) {
|
||||
let lines = s.lines().count();
|
||||
let mut line_numbers = Buffer::empty_from(buf);
|
||||
|
@ -286,12 +286,12 @@ pub(crate) fn print_src(
|
|||
writeln!(line_numbers, "<a href=\"#{line}\" id=\"{line}\">{line}</a>")
|
||||
}
|
||||
}
|
||||
SourceContext::Embedded { url, offset, needs_expansion } => {
|
||||
SourceContext::Embedded { offset, needs_expansion } => {
|
||||
extra =
|
||||
if needs_expansion { Some(r#"<span class="expand">↕</span>"#) } else { None };
|
||||
for line_number in 1..=lines {
|
||||
let line = line_number + offset;
|
||||
writeln!(line_numbers, "<a href=\"{root_path}{url}#{line}\">{line}</a>")
|
||||
writeln!(line_numbers, "<span>{line}</span>")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -575,7 +575,7 @@ ul.block, .block li {
|
|||
border-color: var(--example-line-numbers-border-color);
|
||||
}
|
||||
|
||||
.src-line-numbers a {
|
||||
.src-line-numbers a, .src-line-numbers span {
|
||||
color: var(--src-line-numbers-span-color);
|
||||
}
|
||||
.src-line-numbers :target {
|
||||
|
@ -2061,7 +2061,8 @@ in storage.js
|
|||
padding: 14px 0;
|
||||
}
|
||||
|
||||
.scraped-example .code-wrapper .src-line-numbers a {
|
||||
.scraped-example .code-wrapper .src-line-numbers a,
|
||||
.scraped-example .code-wrapper .src-line-numbers span {
|
||||
padding: 0 14px;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue