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

Documentation: inline code with links split into multiple blocks #83997

Open
tspiteri opened this issue Apr 8, 2021 · 3 comments
Open

Documentation: inline code with links split into multiple blocks #83997

tspiteri opened this issue Apr 8, 2021 · 3 comments
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@tspiteri
Copy link
Contributor

tspiteri commented Apr 8, 2021

EDIT(camelid): ⚠️ Please do not open a PR for this! It is still under discussion.


Right now in the standard library documentation, when a piece of inline code has part of it linked, the code is split into multiple <code> blocks, which renders poorly. For example the Arc thread safety section contains

image

Here, between Arc< and RefCell, and between <T> and >, there is extra spacing. This is because the doc comment contains

/// `Arc<`[`RefCell<T>`]`>`

which is rendered using three <code> blocks as

<code>Arc&lt;</code><a href="../../std/cell/struct.RefCell.html"><code>RefCell&lt;T&gt;</code></a><code>&gt;</code>

I think better would be

/// <code>Arc&lt;[RefCell&lt;T&gt;][RefCell]&gt;</code>

which presumably is rendered in one block as

<code>Arc&lt;<a href="../../std/cell/struct.RefCell.html">RefCell&lt;T&gt;</a>&gt;</code>

(I'm not sure if the link to RefCell gets a title attribute as well).

The downside is that now the doc comment markdown is a bit hairy with explicit <code>, &lt; and &gt; spread throughout.

Is this substitution considered an improvement? If so I can grep through the code, make some substitutions, and open a PR.

An alternative solution would be to change rustdoc itself to combine consecutive code blocks, some of which could be wrapped inside <a>/</a>, into a single block, though I do not have the know-how to open such a PR. I don't even know if there is some downside to this that I am missing, where <code> blocks are meant to be separate, maybe for some markdown compliance or something.

@tspiteri tspiteri changed the title Documentation: inline code with multiple links split into Documentation: inline code with links split into multiple blocks Apr 8, 2021
@jyn514
Copy link
Member

jyn514 commented Apr 8, 2021

Yes, I think this is a good change - one like it has already been accepted (#80720) and I need to merge the other, thanks for reminding me (#80733). I need to open an issue for rustdoc to do this automatically - I don't know if it's worth spending time to convert the whole standard library by hand in the meantime.

An alternative solution would be to change rustdoc itself to combine consecutive code blocks, some of which could be wrapped inside <a>/</a>, into a single block, though I do not have the know-how to open such a PR. I don't even know if there is some downside to this that I am missing, where <code> blocks are meant to be separate, maybe for some markdown compliance or something.

See #80733 (comment) which I think is a very good approach and we might be able to do with CSS only (cc @camelid).

@camelid camelid added C-feature-request Category: A feature request, i.e: not implemented / a PR. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Apr 9, 2021
@camelid camelid self-assigned this Apr 9, 2021
@camelid camelid added the A-rustdoc-ui Area: Rustdoc UI (generated HTML) label Apr 9, 2021
@camelid camelid removed their assignment Apr 9, 2021
@camelid camelid added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed C-feature-request Category: A feature request, i.e: not implemented / a PR. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Apr 9, 2021
@camelid
Copy link
Member

camelid commented Apr 9, 2021

I think we should open a separate issue for changing rustdoc's behavior so it does this automatically, and then close this one. What do you think?

@camelid camelid removed the A-rustdoc-ui Area: Rustdoc UI (generated HTML) label Apr 9, 2021
@camelid
Copy link
Member

camelid commented Apr 9, 2021

Okay, I opened another issue: #84043. I'm not going to close this one without hearing back from other people on what they think, but I added a warning to the top of this issue so someone doesn't put energy into a PR before it is decided what we want to do.

EDIT: That issue is a duplicate of #62867, so I closed the new issue.

bors added a commit to rust-lang-ci/rust that referenced this issue Sep 25, 2021
Fix spacing of links in inline code.

Similar to rust-lang#80733, but the focus is different. This PR eliminates all occurrences of pieced-together inline code blocks like [`Box`]`<`[`Option`]`<T>>` and replaces them with good-looking ones (using HTML-syntax), like <code>[Box]<[Option]\<T>></code>. As far as I can tell, I should’ve found all of these in the standard library (regex search with `` r"`\]`|`\[`" ``) \[except for in `core::convert` where I’ve noticed other things in the docs that I want to fix in a separate PR]. In particular, unlike rust-lang#80733, I’ve added almost no new instance of inline code that’s broken up into multiple links (or some link and some link-free part). I also added tooltips (the stuff in quotes for the markdown link listings) in places that caught my eye, but that’s by no means systematic, just opportunistic.

[Box]: https://doc.rust-lang.org/std/boxed/struct.Box.html "Box"
[`Box`]: https://doc.rust-lang.org/std/boxed/struct.Box.html "Box"
[Option]: https://doc.rust-lang.org/std/option/enum.Option.html "Option"
[`Option`]: https://doc.rust-lang.org/std/option/enum.Option.html "Option"

Context: I got annoyed by repeatedly running into new misformatted inline code while reading the standard library docs. I know that once issue rust-lang#83997 (and/or related ones) are resolved, these changes become somewhat obsolete, but I fail to notice much progress on that end right now.

r? `@jyn514`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants