diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-09-05 18:58:56 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-05 18:58:56 +0200 |
| commit | 9be97ae8e29b99a030a327cdb50e1997a4ff3470 (patch) | |
| tree | 8b78e601cf29af214f649a8b176c342f5f846e10 /src/librustdoc/html/render/mod.rs | |
| parent | 15e7a67b502b2f4729ef39d7a517fe9e762bd438 (diff) | |
| parent | 7157f98cb481766873306238185fb5d4522a903a (diff) | |
| download | rust-9be97ae8e29b99a030a327cdb50e1997a4ff3470.tar.gz rust-9be97ae8e29b99a030a327cdb50e1997a4ff3470.zip | |
Rollup merge of #129796 - GuillaumeGomez:unify-code-examples, r=notriddle
Unify scraped examples with other code examples Fixes #129763. This first PR both fixes #129763 but also unifies buttons display for code examples:  You can test it [here](https://rustdoc.crud.net/imperio/unify-code-examples/doc/scrape_examples/fn.test.html) and [here](https://rustdoc.crud.net/imperio/unify-code-examples/doc/scrape_examples/fn.test_many.html). I'm planning to send a follow-up to make the buttons generated in JS directly (or I can do it in this PR directly if you prefer). cc ```@willcrichton``` r? ```@notriddle```
Diffstat (limited to 'src/librustdoc/html/render/mod.rs')
| -rw-r--r-- | src/librustdoc/html/render/mod.rs | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 095bfe158ff..f67d006116c 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2506,28 +2506,6 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c let needs_expansion = line_max - line_min > NUM_VISIBLE_LINES; let locations_encoded = serde_json::to_string(&line_ranges).unwrap(); - write!( - &mut w, - "<div class=\"scraped-example {expanded_cls}\" data-locs=\"{locations}\">\ - <div class=\"scraped-example-title\">\ - {name} (<a href=\"{url}\">{title}</a>)\ - </div>\ - <div class=\"code-wrapper\">", - expanded_cls = if needs_expansion { "" } else { "expanded" }, - name = call_data.display_name, - url = init_url, - title = init_title, - // The locations are encoded as a data attribute, so they can be read - // later by the JS for interactions. - locations = Escape(&locations_encoded) - ) - .unwrap(); - - if line_ranges.len() > 1 { - w.write_str(r#"<button class="prev">≺</button> <button class="next">≻</button>"#) - .unwrap(); - } - // Look for the example file in the source map if it exists, otherwise return a dummy span let file_span = (|| { let source_map = tcx.sess.source_map(); @@ -2558,9 +2536,16 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c cx, &cx.root_path(), highlight::DecorationInfo(decoration_info), - sources::SourceContext::Embedded { offset: line_min, needs_expansion }, + sources::SourceContext::Embedded(sources::ScrapedInfo { + needs_prev_next_buttons: line_ranges.len() > 1, + needs_expansion, + offset: line_min, + name: &call_data.display_name, + url: init_url, + title: init_title, + locations: locations_encoded, + }), ); - w.write_str("</div></div>").unwrap(); true }; |
