Skip to content

Prevent usage of .stab elements to create scrollable areas in doc blocks #102100

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

Merged
merged 2 commits into from
Sep 22, 2022
Merged
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
6 changes: 6 additions & 0 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,12 @@ so that we can apply CSS-filters to change the arrow color in themes */
margin-right: 0.3rem;
}

/* This is to prevent the `.stab` elements to overflow the .docblock elements. */
.docblock .stab {
padding: 0 0.125em;
margin-bottom: 0;
}

/* Black one-pixel outline around emoji shapes */
.emoji {
text-shadow:
Expand Down
21 changes: 21 additions & 0 deletions src/test/rustdoc-gui/check-stab-in-docblock.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// This test checks that using `.stab` attributes in `.docblock` elements doesn't
// create scrollable paragraphs.
goto: file://|DOC_PATH|/test_docs/index.html
// Needs the text to be display to check for scrollable content.
show-text: true
size: (786, 600)
// Confirms that there 3 paragraphs.
assert-count: (".top-doc .docblock p", 3)
// Checking that there is no scrollable content.
assert-property: (
".top-doc .docblock p:nth-of-type(1)",
{"scrollHeight": "120", "clientHeight": "120", "scrollWidth": "502", "clientWidth": "502"},
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of hard coding the number 502, would it be better to create a fourth paragraph, with no stab tags in it, and use compare-elements-property to assert that they all have the same scroll width?

Copy link
Member Author

Choose a reason for hiding this comment

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

That wouldn't be "accurate" as for whatever reasons the size could be different. What I'm currently working on is adding support for variables in browser-ui-test so we can instead directly store either scroll* or client* and then compare to the other ones, so no need for raw numbers like this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I created the issue so you can have an idea of what it will look like: GuillaumeGomez/browser-UI-test#351

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, that makes sense.

)
assert-property: (
".top-doc .docblock p:nth-of-type(2)",
{"scrollHeight": "48", "clientHeight": "48", "scrollWidth": "502", "clientWidth": "502"},
)
assert-property: (
".top-doc .docblock p:nth-of-type(3)",
{"scrollHeight": "48", "clientHeight": "48", "scrollWidth": "502", "clientWidth": "502"},
)
18 changes: 18 additions & 0 deletions src/test/rustdoc-gui/src/test_docs/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@
#![feature(rustdoc_internals)]
#![feature(doc_cfg)]

/*!
Enable the feature <span class="stab portability"><code>some-feature</code></span> to enjoy
this crate even more!
Enable the feature <span class="stab portability"><code>some-feature</code></span> to enjoy
this crate even more!
Enable the feature <span class="stab portability"><code>some-feature</code></span> to enjoy
this crate even more!

Also, stop using `bar` as it's <span class="stab deprecated" title="">deprecated</span>.
Also, stop using `bar` as it's <span class="stab deprecated" title="">deprecated</span>.
Also, stop using `bar` as it's <span class="stab deprecated" title="">deprecated</span>.

Finally, you can use `quz` only on <span class="stab portability"><code>Unix or x86-64</code>
</span>.
Finally, you can use `quz` only on <span class="stab portability"><code>Unix or x86-64</code>
</span>.
*/

use std::convert::AsRef;
use std::fmt;

Expand Down