Skip to content
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

Improve styling of <span class="stab"> tags in the documentation's main body #101874

Closed
FedericoStra opened this issue Sep 15, 2022 · 2 comments · Fixed by #102100
Closed

Improve styling of <span class="stab"> tags in the documentation's main body #101874

FedericoStra opened this issue Sep 15, 2022 · 2 comments · Fixed by #102100
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@FedericoStra
Copy link
Contributor

FedericoStra commented Sep 15, 2022

The Problem

If one tries to put feature labels in the main body of the documentation (what goes inside <div class="docblock">) they get styled differently from the one automatically inserted by rustdoc running with #![feature(doc_auto_cfg)]. In particular the layout is bad and can cause the appearance of scrollbars on the right hand side of each involved paragraph.

Here is an example picture:

screenshot bad

The desirable look would of course be

screenshot good

Code to generate the example documentation above.

Cargo.toml:

[package]
name = "doc-example"
version = "0.1.0"
edition = "2021"

[features]
default = ["some-feature"]
some-feature = []

src/lib.rs:

/*! Cool library.

<!-- REMOVE TO PRODUCE THE BAD VERSION -->
<style>
.docblock .stab {
    display: inline-block;
    margin-bottom: 0;
    padding: 2px;
    line-height: 1.2;
    border-radius: 3px;
}
</style>

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>.
Finally, you can use [`quz`] only on <span class="stab portability"><code>Unix or x86-64</code></span>.
*/

#![feature(doc_auto_cfg)]

/// Does fooish things.
#[cfg(feature = "some-feature")]
pub fn foo() {}

/// Does barish things.
#[deprecated(since = "0.1.0", note = "we don't need this anymore")]
pub fn bar() {}

/// Does quzish things.
#[cfg(any(unix, target_arch = "x86_64"))]
pub fn quz() {}

The Cause

The reason is that rustdoc.css has a special rule for .module-item .stab, .import-item .stab, whereas it does not address .stab tags appearing as descendant of .docblock tags.

The Fix

From a crate developer's point of view, the fix for this is simple enough: just inject the following CSS

.docblock .stab {
    display: inline-block;
    margin-bottom: 0;
    padding: 2px;
    line-height: 1.2;
    border-radius: 3px;
}

so that they are rendered the same way as the ones generated by rustdoc's doc_auto_cfg labels.

The Request

Is there any chance that this CSS gets included in the official rustdoc.css style?

The fix would probably consist in adding .docblock .stab to

.module-item .stab,
.import-item .stab {
border-radius: 3px;
display: inline-block;
font-size: 0.875rem;
line-height: 1.2;
margin-bottom: 0;
margin-left: 0.3125em;
padding: 2px;
vertical-align: text-bottom;
}

except that we don't want the left margin, so probably a dedicated rule is more appropriate.

@FedericoStra FedericoStra added the C-bug Category: This is a bug. label Sep 15, 2022
@FedericoStra FedericoStra changed the title Improve styling of <span class="stab"> tags in the main body Improve styling of <span class="stab"> tags in the documentation's main body Sep 15, 2022
@FedericoStra
Copy link
Contributor Author

This issue should probably have labels A-rustdoc-ui and T-rustdoc.

@GuillaumeGomez GuillaumeGomez added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-rustdoc-ui Area: Rustdoc UI (generated HTML) labels Sep 21, 2022
@GuillaumeGomez
Copy link
Member

Added the labels and I'll take a look shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants