From cb3a04b6ef4db1b16d5e8dac5fcc00d66183eed6 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 12 Nov 2022 08:53:12 -0700 Subject: [PATCH] rustdoc: avoid excessive HTML generated in example sources --- src/librustdoc/html/render/mod.rs | 6 +----- src/librustdoc/html/sources.rs | 10 +++++----- src/librustdoc/html/static/css/rustdoc.css | 5 +++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index e09106077f7e..1fe52353449b 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -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, ""); diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index 99b4678c4577..50135d601900 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -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, "{line}") } } - SourceContext::Embedded { url, offset, needs_expansion } => { + SourceContext::Embedded { offset, needs_expansion } => { extra = if needs_expansion { Some(r#""#) } else { None }; for line_number in 1..=lines { let line = line_number + offset; - writeln!(line_numbers, "{line}") + writeln!(line_numbers, "{line}") } } } diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index b64fe74e960e..bbcce7266685 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -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; }