diff options
| author | Michael Goulet <michael@errs.io> | 2023-02-03 14:15:23 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-03 14:15:23 -0800 |
| commit | f7210b3bedd04bbc5674fadf878a56cde38ed85b (patch) | |
| tree | a168bd96161489926b603f2e5b666deeb1e4a133 /src/librustdoc/html | |
| parent | 1594b58ce78b772aeb4bc8913f7f0c6ea3e0fcc7 (diff) | |
| parent | 784665d4ce59c5239791f1f96fa2137e47ca1817 (diff) | |
| download | rust-f7210b3bedd04bbc5674fadf878a56cde38ed85b.tar.gz rust-f7210b3bedd04bbc5674fadf878a56cde38ed85b.zip | |
Rollup merge of #107615 - notriddle:notriddle/nbsp, r=GuillaumeGomez
Replace nbsp in all rustdoc code blocks Based on #106125 by `@dtolnay` — this PR fixes the line wrapping bug. Fixes #106098. This makes code copyable from rustdoc rendered documentation into a Rust source file.
Diffstat (limited to 'src/librustdoc/html')
| -rw-r--r-- | src/librustdoc/html/format.rs | 20 | ||||
| -rw-r--r-- | src/librustdoc/html/render/print_item.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/html/static/css/rustdoc.css | 2 |
3 files changed, 14 insertions, 12 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 33404a76835..74cdf9b9b79 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -208,7 +208,7 @@ impl clean::GenericParamDef { if f.alternate() { write!(f, ": {:#}", print_generic_bounds(bounds, cx))?; } else { - write!(f, ": {}", print_generic_bounds(bounds, cx))?; + write!(f, ": {}", print_generic_bounds(bounds, cx))?; } } @@ -216,7 +216,7 @@ impl clean::GenericParamDef { if f.alternate() { write!(f, " = {:#}", ty.print(cx))?; } else { - write!(f, " = {}", ty.print(cx))?; + write!(f, " = {}", ty.print(cx))?; } } @@ -226,14 +226,14 @@ impl clean::GenericParamDef { if f.alternate() { write!(f, "const {}: {:#}", self.name, ty.print(cx))?; } else { - write!(f, "const {}: {}", self.name, ty.print(cx))?; + write!(f, "const {}: {}", self.name, ty.print(cx))?; } if let Some(default) = default { if f.alternate() { write!(f, " = {:#}", default)?; } else { - write!(f, " = {}", default)?; + write!(f, " = {}", default)?; } } @@ -354,12 +354,12 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>( let mut br_with_padding = String::with_capacity(6 * indent + 28); br_with_padding.push_str("<br>"); for _ in 0..indent + 4 { - br_with_padding.push_str(" "); + br_with_padding.push_str(" "); } let where_preds = where_preds.to_string().replace("<br>", &br_with_padding); if ending == Ending::Newline { - let mut clause = " ".repeat(indent.saturating_sub(1)); + let mut clause = " ".repeat(indent.saturating_sub(1)); write!(clause, "<span class=\"where fmt-newline\">where{where_preds},</span>")?; clause } else { @@ -368,7 +368,7 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>( format!("<br><span class=\"where\">where{where_preds}</span>") } else { let mut clause = br_with_padding; - clause.truncate(clause.len() - 4 * " ".len()); + clause.truncate(clause.len() - 4); write!(clause, "<span class=\"where\">where{where_preds}</span>")?; clause } @@ -1391,8 +1391,8 @@ impl clean::FnDecl { let declaration_len = header_len + args_plain.len() + arrow_plain.len(); let output = if declaration_len > 80 { - let full_pad = format!("<br>{}", " ".repeat(indent + 4)); - let close_pad = format!("<br>{}", " ".repeat(indent)); + let full_pad = format!("<br>{}", " ".repeat(indent + 4)); + let close_pad = format!("<br>{}", " ".repeat(indent)); format!( "({pad}{args}{close}){arrow}", pad = if self.inputs.values.is_empty() { "" } else { &full_pad }, @@ -1611,7 +1611,7 @@ impl clean::TypeBinding { if f.alternate() { write!(f, ": {:#}", print_generic_bounds(bounds, cx))?; } else { - write!(f, ": {}", print_generic_bounds(bounds, cx))?; + write!(f, ": {}", print_generic_bounds(bounds, cx))?; } } } diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index bd7548003ad..9a7a08ab806 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -1157,7 +1157,7 @@ fn item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean: fn print_tuple_struct_fields(w: &mut Buffer, cx: &Context<'_>, s: &[clean::Item]) { for (i, ty) in s.iter().enumerate() { if i > 0 { - w.write_str(", "); + w.write_str(", "); } match *ty.kind { clean::StrippedItem(box clean::StructFieldItem(_)) => w.write_str("_"), @@ -1297,7 +1297,7 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean:: "<div class=\"sub-variant-field\">\ <span id=\"{id}\" class=\"small-section-header\">\ <a href=\"#{id}\" class=\"anchor field\">§</a>\ - <code>{f}: {t}</code>\ + <code>{f}: {t}</code>\ </span>", id = id, f = field.name.unwrap(), diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index ee988090ca3..a1e91118303 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -184,6 +184,7 @@ h4.code-header { font-weight: 600; margin: 0; padding: 0; + white-space: pre-wrap; } #crate-search, @@ -642,6 +643,7 @@ pre, .rustdoc.source .example-wrap { .fn .where, .where.fmt-newline { display: block; + white-space: pre-wrap; font-size: 0.875rem; } |
