rustdoc: avoid excessive HTML generated in example sources
This commit is contained in:
parent
ba4ae13528
commit
cb3a04b6ef
3 changed files with 9 additions and 12 deletions
|
@ -2899,11 +2899,7 @@ fn render_call_locations(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Ite
|
||||||
cx,
|
cx,
|
||||||
&cx.root_path(),
|
&cx.root_path(),
|
||||||
highlight::DecorationInfo(decoration_info),
|
highlight::DecorationInfo(decoration_info),
|
||||||
sources::SourceContext::Embedded {
|
sources::SourceContext::Embedded { offset: line_min, needs_expansion },
|
||||||
url: &call_data.url,
|
|
||||||
offset: line_min,
|
|
||||||
needs_expansion,
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
write!(w, "</div></div>");
|
write!(w, "</div></div>");
|
||||||
|
|
||||||
|
|
|
@ -256,9 +256,9 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) enum SourceContext<'a> {
|
pub(crate) enum SourceContext {
|
||||||
Standalone,
|
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
|
/// 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<'_>,
|
context: &Context<'_>,
|
||||||
root_path: &str,
|
root_path: &str,
|
||||||
decoration_info: highlight::DecorationInfo,
|
decoration_info: highlight::DecorationInfo,
|
||||||
source_context: SourceContext<'_>,
|
source_context: SourceContext,
|
||||||
) {
|
) {
|
||||||
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);
|
||||||
|
@ -286,12 +286,12 @@ pub(crate) fn print_src(
|
||||||
writeln!(line_numbers, "<a href=\"#{line}\" id=\"{line}\">{line}</a>")
|
writeln!(line_numbers, "<a href=\"#{line}\" id=\"{line}\">{line}</a>")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SourceContext::Embedded { url, offset, needs_expansion } => {
|
SourceContext::Embedded { offset, needs_expansion } => {
|
||||||
extra =
|
extra =
|
||||||
if needs_expansion { Some(r#"<span class="expand">↕</span>"#) } else { None };
|
if needs_expansion { Some(r#"<span class="expand">↕</span>"#) } else { None };
|
||||||
for line_number in 1..=lines {
|
for line_number in 1..=lines {
|
||||||
let line = line_number + offset;
|
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);
|
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);
|
color: var(--src-line-numbers-span-color);
|
||||||
}
|
}
|
||||||
.src-line-numbers :target {
|
.src-line-numbers :target {
|
||||||
|
@ -2061,7 +2061,8 @@ in storage.js
|
||||||
padding: 14px 0;
|
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;
|
padding: 0 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue