rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.88k stars 12.52k forks source link

Intra-doc links should be styled according to the kind of their target #78256

Open dfoxfranke opened 3 years ago

dfoxfranke commented 3 years ago

Rustdoc generally has fairly consistent ways of styling documentation items. For example, in the default Light theme, structs are magenta, traits are lavender, functions and methods are gold, etc., and are always set in a sans-serif or monospace font. However, this convention does not seem to get applied to intra-documentation links.

Right now, if I write

/// [Result]

the link will be blue and set in serifs; if I write

/// [`Result`]

it'll be blue and set in monospace.

It would be more attractive and consistent for [Result] to be set in magenta sans-serif, and [`Result`] to be set in magenta monospace.

camelid commented 3 years ago

IIUC intra-doc links are implemented as just constructing a link based on the path to the item, with no styling applied. In other words, they're equivalent to the old-style [Foo](../foo/struct.Foo.html) links. Thus I'm marking this as a feature request.

dfoxfranke commented 3 years ago

Yes, come to think of it, that raises a question: what to do with old-style links? I can think of a few possibilities and they all seem reasonable:

  1. Nothing. You need to use a new-style intra-doc link if you want the styling.
  2. Have rustdoc notice when something is an old-style doc link and apply formatting as if it had been written in new style.
  3. Don't do anything with them in rustdoc, but add a cargo fix pass to rewrite old-style links.
camelid commented 3 years ago

I think we would like go with (1); the other two seem like they would take a lot of work for not much benefit.

jyn514 commented 3 years ago

FWIW there is an issue open for 3, and that would be my preference: https://github.com/rust-lang/rust/issues/75805

detly commented 3 years ago

If you are going to detect the target of a link, why require the backticks for monospacing at all, when the target is an item?

jyn514 commented 3 years ago

@detly the backticks would not be required. Backticks mean the item should be highlighted as code, so rustdoc uses a monospace font for them already.