Skip to content

rustdoc: improve word break opportunities for narrow screens #93538

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

Open
jsha opened this issue Feb 1, 2022 · 2 comments
Open

rustdoc: improve word break opportunities for narrow screens #93538

jsha opened this issue Feb 1, 2022 · 2 comments
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@jsha
Copy link
Contributor

jsha commented Feb 1, 2022

On narrow screens our method signatures often wrap horribly, like this example that wraps right in the middle of a -> return arrow:

image

To fix that specific issue, we can wrap return arrows in a <span> and style that span with white-space: nowrap. There's a similar issue where the browser will break &[T] between the & and the [. We should use the same trick there to prevent breaking.

Also, the browser will never consider a parenthesis wedged between two words to be a word break opportunity. For instance, in fn foo(bar: Baz), the browser will never break between ( and bar. That's actually one of our optimal break locations; it's where rustfmt would break the word. We can tell the browser that's an available option by inserting a <wbr> tag.

Also, when we do have to break up a signature, we'd prefer to keep each parameter name on the same line as its type if possible (again, mimicking rustfmt style). We can achieve this by inserting an &nbsp; between parameter names and types. For instance bar:&nbsp;Baz. We should also use &nbsp; as the space between mut and Bar in &mut Bar. Note that this may be a little hard because that space is added by print_with_space, and the output of print_with_space is used in both HTML and non-HTML contexts.

@jsha jsha 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 Feb 1, 2022
@jsha
Copy link
Contributor Author

jsha commented Feb 6, 2022

Another possibility: We could do like pkg.go.dev does (e.g. https://pkg.go.dev/crypto/tls#ClientHelloInfo.SupportsCertificate), and set these CSS properties on the method headings:

white-space: pre-wrap;
word-break: break-all;
word-wrap: break-word;

That would cause us to always put as much text as possible on a line, and break right at the end. That would still, allow breaking in the middle of a return arrow, or other awkward breaks. But it might be clearer that a break happened, since the pattern is consistent and the line is filled.

Also worth noting: One of the confusing things in the screenshot above is the collision with the source link, which will be fixed in #93537.

@Enyium
Copy link

Enyium commented Aug 3, 2024

I wondered why text in the right column of this documentation has strange line breaks in the middle of words like "to show th<br>e Slint documentation" or "for red, gr<br>een, blue". The respective <div>s have the CSS word-break: break-all; applied, which rustdoc seems to be responsible for. At least for me in a desktop browser, I'm against this in favor of regular line breaks between words.

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) T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants