Skip to content

Update rustdoc code blocks so they use grid: display #105894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,11 @@ ul.block, .block li {
}

.rustdoc .example-wrap {
display: flex;
display: grid;
grid-template-columns: max-content auto;
position: relative;
margin-bottom: 10px;
overflow-x: auto;
}
/* For the last child of a div, the margin will be taken care of
by the margin-top of the next item. */
Expand All @@ -539,13 +541,15 @@ ul.block, .block li {

.rustdoc .example-wrap > pre {
margin: 0;
flex-grow: 1;
overflow-x: auto;
}
.rustdoc .example-wrap > pre:first-child:last-child {
/* When there is only one "column", we need to only apply "auto" from "grid-template-columns",
otherwise it won't take the full width. */
grid-column-start: 2;
}

.rustdoc .example-wrap > pre.example-line-numbers,
.rustdoc .example-wrap > pre.src-line-numbers {
flex-grow: 0;
overflow: initial;
text-align: right;
-webkit-user-select: none;
Expand Down Expand Up @@ -1978,8 +1982,6 @@ in storage.js
}

.scraped-example .code-wrapper .example-wrap {
display: grid;
grid-template-columns: max-content auto;
width: 100%;
overflow-x: auto;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overflow rule is redundant now, since the overflow-x is now set on all example-wrap blocks. For simplicity’s sake, overflow-y can also be lifted up to there.

overflow-y: hidden;
Expand Down
16 changes: 13 additions & 3 deletions src/test/rustdoc-gui/code-blocks-overflow.goml
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
// This test ensures that codeblocks content don't overflow.
goto: "file://" + |DOC_PATH| + "/lib2/sub_mod/struct.Foo.html"
size: (1080, 600)
// There should be two codeblocks: a rust one and a non-rust one.
assert-count: (".docblock > .example-wrap", 2)
// There should be three codeblocks: two rust ones and a non-rust one.
assert-count: (".docblock > .example-wrap", 3)
assert: ".docblock > .example-wrap > .language-txt"
assert: ".docblock > .example-wrap > .rust-example-rendered"
assert-css: (".docblock > .example-wrap > pre", {"width": "796px", "overflow-x": "auto"}, ALL)

// We confirm that we don't display line numbers currently.
assert-local-storage-false: {"rustdoc-line-numbers": "true"}

assert-css: (".docblock > .example-wrap", {"width": "796px", "overflow-x": "auto"}, ALL)
assert-css: (".docblock > .example-wrap > pre", {"width": "1756px"})

// Confirm that there is no change when line numbers are displayed.
local-storage: {"rustdoc-line-numbers": "true"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test only works if you reload the page.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!

assert-css: (".docblock > .example-wrap", {"width": "796px", "overflow-x": "auto"}, ALL)
assert-css: (".docblock > .example-wrap > pre", {"width": "1756px"})
5 changes: 3 additions & 2 deletions src/test/rustdoc-gui/source-anchor-scroll.goml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// We check that when the anchor changes and is output of the displayed content,
// the page is scrolled to it.
goto: "file://" + |DOC_PATH| + "/src/link_to_definition/lib.rs.html"
show-text: true

// We reduce the window size to make it easier to make an element "out of the page".
size: (600, 800)
Expand All @@ -12,9 +13,9 @@ assert-property: ("html", {"scrollTop": "125"})
click: '//a[text() = "bar"]'
assert-property: ("html", {"scrollTop": "156"})
click: '//a[text() = "sub_fn"]'
assert-property: ("html", {"scrollTop": "53"})
assert-property: ("html", {"scrollTop": "76"})

// We now check that clicking on lines doesn't change the scroll
// Extra information: the "sub_fn" function header is on line 1.
click: '//*[@id="6"]'
assert-property: ("html", {"scrollTop": "53"})
assert-property: ("html", {"scrollTop": "76"})
4 changes: 4 additions & 0 deletions src/test/rustdoc-gui/src/lib2/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ pub mod sub_mod {
/// ```
/// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
/// ```
///
/// ```
/// foo();
/// ```
pub struct Foo;
}

Expand Down