Skip to content

Commit c5f92ce

Browse files
authored
Rollup merge of #104611 - notriddle:notriddle/scrape-examples-button, r=GuillaumeGomez
rustdoc: use real buttons for scrape examples controls This makes the expand and switch controls keyboard-accessible. Preview: https://notriddle.com/notriddle-rustdoc-demos/scrape-examples-button/test_dingus/fn.test.html
2 parents db5f005 + a3ae6fe commit c5f92ce

File tree

11 files changed

+77
-5
lines changed

11 files changed

+77
-5
lines changed

src/bootstrap/test.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,8 @@ impl Step for RustdocGUI {
10111011
// instead of hard-coding this test
10121012
if entry.file_name() == "link_to_definition" {
10131013
cargo.env("RUSTDOCFLAGS", "-Zunstable-options --generate-link-to-definition");
1014+
} else if entry.file_name() == "scrape_examples" {
1015+
cargo.arg("-Zrustdoc-scrape-examples=examples");
10141016
}
10151017
builder.run(&mut cargo);
10161018
}

src/librustdoc/html/render/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2915,7 +2915,7 @@ fn render_call_locations(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Ite
29152915
);
29162916

29172917
if line_ranges.len() > 1 {
2918-
write!(w, r#"<span class="prev">&pr;</span> <span class="next">&sc;</span>"#);
2918+
write!(w, r#"<button class="prev">&pr;</button> <button class="next">&sc;</button>"#);
29192919
}
29202920

29212921
// Look for the example file in the source map if it exists, otherwise return a dummy span

src/librustdoc/html/sources.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,11 @@ pub(crate) fn print_src(
287287
}
288288
}
289289
SourceContext::Embedded { offset, needs_expansion } => {
290-
extra =
291-
if needs_expansion { Some(r#"<span class="expand">&varr;</span>"#) } else { None };
290+
extra = if needs_expansion {
291+
Some(r#"<button class="expand">&varr;</button>"#)
292+
} else {
293+
None
294+
};
292295
for line_number in 1..=lines {
293296
let line = line_number + offset;
294297
writeln!(line_numbers, "<span>{line}</span>")

src/librustdoc/html/static/css/rustdoc.css

+6
Original file line numberDiff line numberDiff line change
@@ -1965,6 +1965,12 @@ in storage.js
19651965
top: 0.25em;
19661966
z-index: 1;
19671967
cursor: pointer;
1968+
padding: 0;
1969+
background: none;
1970+
border: none;
1971+
/* iOS button gradient: https://stackoverflow.com/q/5438567 */
1972+
-webkit-appearance: none;
1973+
opacity: 1;
19681974
}
19691975
.scraped-example .code-wrapper .prev {
19701976
right: 2.25em;

src/librustdoc/html/templates/page.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
{%- endif -%}
4141
<script defer src="{{static_root_path|safe}}{{files.main_js}}"></script> {#- -#}
4242
{%- if layout.scrape_examples_extension -%}
43-
<script defer src="{{page.root_path|safe}}{{files.scrape_examples_js}}"></script> {#- -#}
43+
<script defer src="{{static_root_path|safe}}{{files.scrape_examples_js}}"></script> {#- -#}
4444
{%- endif -%}
4545
<noscript> {#- -#}
4646
<link rel="stylesheet" {# -#}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
goto: "file://" + |DOC_PATH| + "/scrape_examples/fn.test.html"
2+
store-property: (smallOffsetHeight, ".scraped-example-list > .scraped-example pre", "offsetHeight")
3+
assert-property-false: (".scraped-example-list > .scraped-example pre", {
4+
"scrollHeight": |smallOffsetHeight|
5+
})
6+
focus: ".scraped-example-list > .scraped-example .expand"
7+
press-key: "Enter"
8+
assert-property-false: (".scraped-example-list > .scraped-example pre", {
9+
"offsetHeight": |smallOffsetHeight|
10+
})
11+
store-property: (fullOffsetHeight, ".scraped-example-list > .scraped-example pre", "offsetHeight")
12+
assert-property: (".scraped-example-list > .scraped-example pre", {
13+
"scrollHeight": |fullOffsetHeight|
14+
})

src/test/rustdoc-gui/sidebar-source-code.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ assert: "//*[@class='dir-entry' and @open]/*[text()='sub_mod']"
2828
// Only "another_folder" should be "open" in "lib2".
2929
assert: "//*[@class='dir-entry' and not(@open)]/*[text()='another_mod']"
3030
// All other trees should be collapsed.
31-
assert-count: ("//*[@id='source-sidebar']/details[not(text()='lib2') and not(@open)]", 6)
31+
assert-count: ("//*[@id='source-sidebar']/details[not(text()='lib2') and not(@open)]", 7)
3232

3333
// We now switch to mobile mode.
3434
size: (600, 600)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file is automatically @generated by Cargo.
2+
# It is not intended for manual editing.
3+
version = 3
4+
5+
[[package]]
6+
name = "scrape_examples"
7+
version = "0.1.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "scrape_examples"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
fn main() {
2+
for i in 0..9 {
3+
println!("hello world!");
4+
println!("hello world!");
5+
println!("hello world!");
6+
println!("hello world!");
7+
println!("hello world!");
8+
println!("hello world!");
9+
println!("hello world!");
10+
println!("hello world!");
11+
println!("hello world!");
12+
}
13+
scrape_examples::test();
14+
for i in 0..9 {
15+
println!("hello world!");
16+
println!("hello world!");
17+
println!("hello world!");
18+
println!("hello world!");
19+
println!("hello world!");
20+
println!("hello world!");
21+
println!("hello world!");
22+
println!("hello world!");
23+
println!("hello world!");
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// # Examples
2+
///
3+
/// ```
4+
/// test();
5+
/// test();
6+
/// ```
7+
pub fn test() {}

0 commit comments

Comments
 (0)