-
Notifications
You must be signed in to change notification settings - Fork 13k
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 links in inline code in core::pin
.
#80733
Conversation
…ks using HTML-syntax.
…ual consistency.
…the markdown link definition names being case insensitive.
r? @sfackler (rust-highfive has picked a reviewer for you, use r? to override) |
Remarks for review:
|
r? @rust-lang/docs |
Is it necessary to have all the links clickable? Like those |
We have made all the types clickable if possible and (imo), it makes it much more nice to use. @steffahn I have to admit, this is a bit weird to use a |
@pickfire I also like the almost source-code-formatting like nature of having things be links. Another aspect is that next to being clickable, you can also get a tooltip by hovering over the links that can include a more complete path. E.g. the @GuillaumeGomez Yes, as I said So I agree that coherence has its value, but we could easily change other places, too, and coherently use a different solution. One main point of this PR is indeed that I’m not sure how far I can take this use of Also I don’t believe we should be necessarily going all the way as I’ve done in this PR throughout the whole standard library. I think the documentation of |
Just to be clear: I didn't mean it in a negative way, I like the output. Just don't know what we should about it. |
Procedural note: the docs team no longer exists, and so this is up to @rust-lang/libs to decide, formally speaking. |
Do we have a style guide or anything we can use to document any of these workarounds we come up with? Without something like that I have a mild preference against using This is definitely an improvement over [ |
@jyn514 @camelid I'd like to hear your thoughts about this as well. Is this something rustdoc could/should help with in the future? (Either with automatic linking, or by merging code blocks, or in some other way.) And if not, do you think this is something we should start doing manually, like in this PR? |
I'm not sure we should add handlings about this in rustdoc because it could be an issue in case you actually wanted it to look like that (and that'd make it impossible to revert...). |
We've thought about automatic linking before (see #62834 (comment)), However, I've thought before about merging code blocks as you suggested, and I (Imagine that the outer corners of each group of inline code are rounded.) The generated HTML for <a><code class="inline-code-left">Vec</code></a>
<code class="inline-code-inner"><</code>
<a><code class="inline-code-inner">Option</code></a>
<code class="inline-code-right"><T>></code> And things like <a><code>Vec</code></a> What do you think of that @GuillaumeGomez? (By the way, jyn514 is on break so he may not respond to pings.) |
Personally (not speaking on behalf of T-rustdoc), I would try to avoid using However, it's just a formatting decision, so you can also remove all the |
Markdown is a superset of HTML, anything that parses markdown has to deal with HTML already. https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/warning.20sections.20in.20rustdoc.3A.20.2379677/near/218945328 |
@jyn514 It's not entirely true (even though it's not wrong). Let's say markdown supports HTML but it's definitely not intended to be over-using it. |
Yes, I know that technically tools have to deal with it, but if you're translating to LaTeX it's likely it will just ignore HTML. So, it's better in that case to just not use it in the first place if you can avoid it. |
r? @KodrAus |
📌 Commit 3e0cef7 has been approved by |
Improve links in inline code in `core::pin`. ## Context So I recently opened rust-lang#80720. That PR uses HTML-based `<code>foo</code>` syntax in place of `` `foo` `` for some inline code. It looks like usage of `<code>` tags in doc comments is without precedent in the standard library, but the HTML-based syntax has an important advantage: You can write something like ``` <code>[Box]<[Option]\<T>></code> ``` which becomes: <code>[Box]<[Option]\<T>></code>, whereas with ordinary backtick syntax, you cannot create links for a substring of an inline code block. ## Problem I recalled (from my own experience) that a way to partially work around this limitation is to do something like ``` [`Box`]`<`[`Option`]`<T>>` ``` which looks like this: [`Box`]`<`[`Option`]`<T>>` _(admitted, it looks even worse on GitHub than in `rustdoc`’s CSS)_. [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" [Pin]: https://doc.rust-lang.org/std/pin/struct.Pin.html "Pin" [&mut]: https://doc.rust-lang.org/std/primitive.reference.html "mutable reference" So I searched the standard library and found that e.g. the [std::pin](https://doc.rust-lang.org/std/pin/index.html) module documentation uses this hack/workaround quite a bit, with types like <code>[Pin]<[Box]\<T>></code> or <code>[Pin]<[&mut] T>></code>. Although the way they look like in this sentence is what I would like them to look like, not what they currently look. ### Status Quo Here’s a screenshot of what it currently looks like: ![Screenshot_20210105_202751](https://user-images.githubusercontent.com/3986214/103692608-4a978780-4f98-11eb-9451-e13622b2e3c0.png) With a few HTML-style code blocks, we can fix all the spacing issues in the above screenshot that are due usage of this hack/workaround of putting multiple code blocks right next to each other being used. ### after d3915c5: ![Screenshot_20210105_202932](https://user-images.githubusercontent.com/3986214/103692688-6f8bfa80-4f98-11eb-9be5-9b370eaef644.png) There’s still a problem of inconsistency. Especially in a sentence such as > A [`Pin<P>`][Pin] where `P: Deref` should be considered as a "`P`-style pointer" to _[...]_ looks weird with the variable `P` having different colors (and `Deref` has a different color from before where it was a link, too). Or compare the difference of <code>[Pin]<[Box]\<T>></code> vs [`Box<T>`][Box] where one time the variable is part of the link and the other time it isn’t. _Note: Color differences show even **more strongly** when the ayu theme is used, while they are a bit less prominent in the light theme than they are in the dark theme, which is the one used for these screenshots._ This is why I’ve added the next commit ### after ceaeb24 ![Screenshot_20210105_203113](https://user-images.githubusercontent.com/3986214/103693496-ab738f80-4f99-11eb-942d-29dace459734.png) pulling all the type parameters out of their links, and also the last commit with clearly visible changes ### after 87ac118 ![Screenshot_20210105_203252](https://user-images.githubusercontent.com/3986214/103693625-e5dd2c80-4f99-11eb-91b7-470c37934e7e.png) where more links are added, removing e.g. the inconsistency with `Deref`’s color in e.g. `P: Deref` that I already mentioned above. ## Discussion I am aware that this PR may very well be overkill. If for now only the first commit (plus the fix for the `Drop` link in e65385f, the link titles 684edf7 as far as they apply, and a few of the line-break changes) are wanted, I can reduce this PR to just those changes. I personally find the rendered result with all these changes very nice though. On the other hand, all these `<code>` tags are not very nice in the source code, I’ll admit. Perhaps alternative solutions could be preferred, such as `rustdoc` support for merging subsequent inline code blocks so that all the cases that currently use workarounds rendered as [`Box`]`<`[`Option`]`<T>>` automatically become <code>[Box]<[Option]\<T>></code> without any need for further changes. Even in this case, having a properly formatted, better looking example in the standard library docs could help motivate such a change to `rustdoc` by prodiving an example of the expected results and also the already existing alternative (i.e. using `<code>`). On the other hand, `` [`Box`]`<`[`Option`]`<T>>` `` isn’t particularly nice-looking source code either. I’m not even sure if I wouldn’t actually find the version `<code>[Box]<[Option]\<T>></code>` cleaner to read. `@rustbot` modify labels: T-doc, T-rustdoc
⌛ Testing commit 3e0cef7 with merge 4a284ada2697c68939384e25c77a9600a479ab66... |
💔 Test failed - checks-actions |
@jyn514 a step called “install MinGW” failed in CI AFAICT. You set “waiting-on-author”, but there isn’t anything I can do about this, is there? |
Oh sorry, I didn't actually read the CI error. @bors retry |
Rollup of 6 pull requests Successful merges: - rust-lang#80733 (Improve links in inline code in `core::pin`.) - rust-lang#81764 (Stabilize `rustdoc::bare_urls` lint) - rust-lang#81938 (Stabilize `peekable_peek_mut`) - rust-lang#83980 (Fix outdated crate names in compiler docs) - rust-lang#83992 (Merge idents when generating source content) - rust-lang#84001 (Update Clippy) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
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`
Context
So I recently opened #80720. That PR uses HTML-based
<code>foo</code>
syntax in place of`foo`
for some inline code. It looks like usage of<code>
tags in doc comments is without precedent in the standard library, but the HTML-based syntax has an important advantage:You can write something like
which becomes:
Box<Option<T>>
, whereas with ordinary backtick syntax, you cannot create links for a substring of an inline code block.Problem
I recalled (from my own experience) that a way to partially work around this limitation is to do something like
which looks like this:
Box
<
Option
<T>>
(admitted, it looks even worse on GitHub than inrustdoc
’s CSS).So I searched the standard library and found that e.g. the std::pin module documentation uses this hack/workaround quite a bit, with types like
Pin<Box<T>>
orPin<&mut T>>
. Although the way they look like in this sentence is what I would like them to look like, not what they currently look.Status Quo
Here’s a screenshot of what it currently looks like:
With a few HTML-style code blocks, we can fix all the spacing issues in the above screenshot that are due usage of this hack/workaround of putting multiple code blocks right next to each other being used.
after d3915c5:
There’s still a problem of inconsistency. Especially in a sentence such as
looks weird with the variable
P
having different colors (andDeref
has a different color from before where it was a link, too). Or compare the difference ofPin<Box<T>>
vsBox<T>
where one time the variable is part of the link and the other time it isn’t.Note: Color differences show even more strongly when the ayu theme is used, while they are a bit less prominent in the light theme than they are in the dark theme, which is the one used for these screenshots.
This is why I’ve added the next commit
after ceaeb24
pulling all the type parameters out of their links, and also the last commit with clearly visible changes
after 87ac118
where more links are added, removing e.g. the inconsistency with
Deref
’s color in e.g.P: Deref
that I already mentioned above.Discussion
I am aware that this PR may very well be overkill. If for now only the first commit (plus the fix for the
Drop
link in e65385f, the link titles 684edf7 as far as they apply, and a few of the line-break changes) are wanted, I can reduce this PR to just those changes. I personally find the rendered result with all these changes very nice though. On the other hand, all these<code>
tags are not very nice in the source code, I’ll admit.Perhaps alternative solutions could be preferred, such as
rustdoc
support for merging subsequent inline code blocks so that all the cases that currently use workarounds rendered asBox
<
Option
<T>>
automatically becomeBox<Option<T>>
without any need for further changes. Even in this case, having a properly formatted, better looking example in the standard library docs could help motivate such a change torustdoc
by prodiving an example of the expected results and also the already existing alternative (i.e. using<code>
). On the other hand,[`Box`]`<`[`Option`]`<T>>`
isn’t particularly nice-looking source code either. I’m not even sure if I wouldn’t actually find the version<code>[Box]<[Option]\<T>></code>
cleaner to read.@rustbot modify labels: T-doc, T-rustdoc