rust/tests/rustdoc-ui/issues
bors 05965ae238 Auto merge of #124577 - GuillaumeGomez:stabilize-custom_code_classes_in_docs, r=rustdoc
Stabilize `custom_code_classes_in_docs` feature

Fixes #79483.

This feature has been around for quite some time now, I think it's fine to stabilize it now.

## Summary

## What is the feature about?

In short, this PR changes two things, both related to codeblocks in doc comments in Rust documentation:

 * Allow to disable generation of `language-*` CSS classes with the `custom` attribute.
 * Add your own CSS classes to a code block so that you can use other tools to highlight them.

#### The `custom` attribute

Let's start with the new `custom` attribute: it will disable the generation of the `language-*` CSS class on the generated HTML code block. For example:

```rust
/// ```custom,c
/// int main(void) {
///     return 0;
/// }
/// ```
```

The generated HTML code block will not have `class="language-c"` because the `custom` attribute has been set. The `custom` attribute becomes especially useful with the other thing added by this feature: adding your own CSS classes.

#### Adding your own CSS classes

The second part of this feature is to allow users to add CSS classes themselves so that they can then add a JS library which will do it (like `highlight.js` or `prism.js`), allowing to support highlighting for other languages than Rust without increasing burden on rustdoc. To disable the automatic `language-*` CSS class generation, you need to use the `custom` attribute as well.

This allow users to write the following:

```rust
/// Some code block with `{class=language-c}` as the language string.
///
/// ```custom,{class=language-c}
/// int main(void) {
///     return 0;
/// }
/// ```
fn main() {}
```

This will notably produce the following HTML:

```html
<pre class="language-c">
int main(void) {
    return 0;
}</pre>
```

Instead of:

```html
<pre class="rust rust-example-rendered">
<span class="ident">int</span> <span class="ident">main</span>(<span class="ident">void</span>) {
    <span class="kw">return</span> <span class="number">0</span>;
}
</pre>
```

To be noted, we could have written `{.language-c}` to achieve the same result. `.` and `class=` have the same effect.

One last syntax point: content between parens (`(like this)`) is now considered as comment and is not taken into account at all.

In addition to this, I added an `unknown` field into `LangString` (the parsed code block "attribute") because of cases like this:

```rust
/// ```custom,class:language-c
/// main;
/// ```
pub fn foo() {}
```

Without this `unknown` field, it would generate in the DOM: `<pre class="language-class:language-c language-c">`, which is quite bad. So instead, it now stores all unknown tags into the `unknown` field and use the first one as "language". So in this case, since there is no unknown tag, it'll simply generate `<pre class="language-c">`. I added tests to cover this.

EDIT(camelid): This description is out-of-date. Using `custom,class:language-c` will generate the output `<pre class="language-class:language-c">` as would be expected; it treats `class:language-c` as just the name of a language (similar to the langstring `c` or `js` or what have you) since it does not use the designed class syntax.

Finally, I added a parser for the codeblock attributes to make it much easier to maintain. It'll be pretty easy to extend.

As to why this syntax for adding attributes was picked: it's [Pandoc's syntax](https://pandoc.org/MANUAL.html#extension-fenced_code_attributes). Even if it seems clunkier in some cases, it's extensible, and most third-party Markdown renderers are smart enough to ignore Pandoc's brace-delimited attributes (from [this comment](https://github.com/rust-lang/rust/pull/110800#issuecomment-1522044456)).

r? `@notriddle`
2024-06-01 10:18:01 +00:00
..
auxiliary [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-58473-2.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-58473.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-61592-2.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-61592-2.stderr Bless rustdoc-ui tests 2023-11-24 19:15:52 +01:00
issue-61592.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-61592.stderr Bless rustdoc-ui tests 2023-11-24 19:15:52 +01:00
issue-61732.rs Move some rustdoc-ui tests to subdirectories 2023-04-29 11:36:19 -05:00
issue-61732.stderr Bless rustdoc-ui tests 2023-11-24 19:15:52 +01:00
issue-74134.private.stderr Move some rustdoc-ui tests to subdirectories 2023-04-29 11:36:19 -05:00
issue-74134.public.stderr Move some rustdoc-ui tests to subdirectories 2023-04-29 11:36:19 -05:00
issue-74134.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-79465.rs Move some rustdoc-ui tests to subdirectories 2023-04-29 11:36:19 -05:00
issue-79465.stderr Bless rustdoc-ui tests 2023-11-24 19:15:52 +01:00
issue-79467.rs Move some rustdoc-ui tests to subdirectories 2023-04-29 11:36:19 -05:00
issue-79467.stderr Bless rustdoc-ui tests 2023-11-24 19:15:52 +01:00
issue-79494.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-79494.stderr Manual find replace updates 2023-11-24 21:04:51 +01:00
issue-80992.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-80992.stdout Move some rustdoc-ui tests to subdirectories 2023-04-29 11:36:19 -05:00
issue-81662-shortness.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-81662-shortness.stdout Switch from using //~ERROR annotations with --error-format to error-pattern 2023-12-21 16:45:29 +05:30
issue-83883-describe-lints.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-83883-describe-lints.stdout Remove support for compiler plugins. 2023-11-04 08:50:46 +11:00
issue-91134.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-91134.stdout Move some rustdoc-ui tests to subdirectories 2023-04-29 11:36:19 -05:00
issue-91713.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-91713.stderr Move some rustdoc-ui tests to subdirectories 2023-04-29 11:36:19 -05:00
issue-91713.stdout Auto merge of #124577 - GuillaumeGomez:stabilize-custom_code_classes_in_docs, r=rustdoc 2024-06-01 10:18:01 +00:00
issue-96287.rs Bless test fallout (duplicate diagnostics) 2024-03-20 13:00:34 -04:00
issue-96287.stderr Bless test fallout (duplicate diagnostics) 2024-03-20 13:00:34 -04:00
issue-98690.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-98690.stderr Move some rustdoc-ui tests to subdirectories 2023-04-29 11:36:19 -05:00
issue-101076.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-102986.rs Move some rustdoc-ui tests to subdirectories 2023-04-29 11:36:19 -05:00
issue-102986.stderr Already poison the type_of result of the anon const used in the typeof expression 2024-02-08 07:32:30 +00:00
issue-103997.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-103997.stderr Move some rustdoc-ui tests to subdirectories 2023-04-29 11:36:19 -05:00
issue-105334.rs Move some rustdoc-ui tests to subdirectories 2023-04-29 11:36:19 -05:00
issue-105334.stderr Bless rustdoc-ui tests 2023-11-24 19:15:52 +01:00
issue-105737.rs Move some rustdoc-ui tests to subdirectories 2023-04-29 11:36:19 -05:00
issue-105737.stderr Bless rustdoc-ui tests 2023-11-24 19:15:52 +01:00
issue-105742.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-105742.stderr Merge collect_mod_item_types query into check_well_formed 2024-03-07 14:26:31 +00:00
issue-106213.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-106213.stderr Bless rustdoc-ui tests 2023-11-24 19:15:52 +01:00
issue-106226.rs Move some rustdoc-ui tests to subdirectories 2023-04-29 11:36:19 -05:00
issue-106226.stderr Bless rustdoc-ui tests 2023-11-24 19:15:52 +01:00
issue-107918.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-109282-import-inline-merge.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-110900.rs Stabilize associated type bounds 2024-03-08 20:56:25 +00:00
issue-120444-1.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-120444-1.stderr docs: also check the inline stmt during redundant link check 2024-02-07 15:43:32 +08:00
issue-120444-2.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-120444-2.stderr docs: also check the inline stmt during redundant link check 2024-02-07 15:43:32 +08:00