diff options
| author | Guillaume Gomez <guillaume.gomez@huawei.com> | 2024-08-30 18:27:11 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume.gomez@huawei.com> | 2024-08-31 00:12:16 +0200 |
| commit | 0d156f223a3fb389f813d8fdb0b588f95b3868aa (patch) | |
| tree | e38d8e0cefb9f8c09dc4faf34a4e808904f88fc7 /src/librustdoc/html/render/mod.rs | |
| parent | 0d634185dfddefe09047881175f35c65d68dcff1 (diff) | |
| download | rust-0d156f223a3fb389f813d8fdb0b588f95b3868aa.tar.gz rust-0d156f223a3fb389f813d8fdb0b588f95b3868aa.zip | |
Unify scraped examples with other code examples
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 47f321a4c4a..0a18944977f 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2445,28 +2445,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(); @@ -2497,9 +2475,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 }; |
