Accept additional user-defined syntax classes in fenced code blocks#110800
Accept additional user-defined syntax classes in fenced code blocks#110800bors merged 13 commits intorust-lang:masterfrom
Conversation
This comment has been minimized.
This comment has been minimized.
91757a8 to
69572ff
Compare
This comment has been minimized.
This comment has been minimized.
69572ff to
56bd628
Compare
|
Fixed the feature version errors. |
|
I'm surprised that it's not aligning the syntax more closely with RFC 3311. Last time, on that RFC, I did a Babelmark run to try to design a syntax that would produce reasonable results in most Markdown parsers. The important thing is that this syntax should gracefully degrade in mdBook, docs.rs, crates.io, GitHub, and other widely-used Markdown renderers, so that people can use p.s. I still think we should align Rustdoc's handling of code strings as closely as possible with Pandoc's. 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. |
notriddle
left a comment
There was a problem hiding this comment.
Babelmark run for the proposed syntax shows that this syntax behaves badly in other markdown parsers.
I wasn't aware of it. Using About following pandoc, it depends on one big thing: do we want to allow code-blocks to have user-defined IDs? Also, as you mentioned, it's a bit clunkier. EDIT: In any case, both solutions sound good to me. But I really find the pandoc one ugly. ^^' EDIT2: Thinking about it some more, using an existing syntax would actually be wiser so I think going for the pandoc one is the right move here. I'll update the PR for it and specifically reject Note for myself: should only allow for |
We've already got two features that want key-value pairs here (RFC 3311, and this one). It seems pretty arbitrary to think there won't be more.
I know their documentation always shows key=value pairs with quoted values, but you don't actually need to quote them. Here's an example where |
56bd628 to
03dd1a2
Compare
|
I switched to the pandoc syntax as suggested and created a new parser for the markdown codeblock attributes. Any attribute which is not a class (so either |
03dd1a2 to
0763193
Compare
|
I added the suggested tests, I updated the documentation and I added the support for double quotes (which is much more permissive than pandoc's). |
|
I'd like to create an eBNF to describe this grammar. There's a few aspects of it, like the way quotes and dots are handled, that make writing one difficult. Would you be okay with making this syntax a lot stricter in order to make it easier to write a spec? |
|
I'm open to it. The current handling could have an eBNF as well I think. But you seem like you have an idea for a syntax so don't hesitate to suggest an eBNF. :) |
|
Alright, I've put together an eBNF that seems to "fit the spirit of this change," by passing many of the test cases and generally acting "reasonable." It, and a |
|
Some noticeable differences between the two of them:
Some notable similarities:
All of this stuff should be changeable, if any of it is a problem (though none of it seems too onerous to me). |
|
☔ The latest upstream changes (presumably #111001) made this pull request unmergeable. Please resolve the merge conflicts. |
0a6a99c to
ed4a959
Compare
This comment has been minimized.
This comment has been minimized.
ed4a959 to
6cdddd9
Compare
|
☀️ Test successful - checks-actions |
|
Finished benchmarking commit (41bafc4): comparison URL. Overall result: ❌ regressions - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 632.782s -> 631.931s (-0.13%) |
|
Is it possible that this caused a regression? We're seeing rustdoc errors about "custom classes" on nightly Miri CI since this morning. See Zulip. |
|
Yes, it should emit a warning and not an error. I'll fix this right away. |
…ses_in_docs-into-warning, r=Manishearth Turn custom code classes in docs into warning By habit, since it was a new feature gate, I added a check which emitted an error in case the new syntax was used. However, since rustdoc tags parser was accepting *everything*, using the "new" syntax should never ever emit errors. It now emits a warning. Follow-up of rust-lang#110800. cc `@Manishearth` r? `@notriddle`
…ses_in_docs-into-warning, r=Manishearth Turn custom code classes in docs into warning By habit, since it was a new feature gate, I added a check which emitted an error in case the new syntax was used. However, since rustdoc tags parser was accepting *everything*, using the "new" syntax should never ever emit errors. It now emits a warning. Follow-up of rust-lang#110800. cc `@Manishearth` r? `@notriddle`
286: Bugfix for text codeblock in documentation. r=cuviper a=robamu Fixes #285 . From what I have seen, the local output generated with `cargo +nightly doc --open` (rustc v1.74.0 nightly 203c57dbe) does not look differently than the most current one found here: https://docs.rs/num-traits/latest/num_traits/identities/trait.One.html Propably related to rust-lang/rust#110800 ? If it is, then the issue might be fixed soon and this PR should be ignored.. Co-authored-by: Robin Mueller <robin.mueller.m@gmail.com>
…_in_docs-warning, r=notriddle Custom code classes in docs warning Fixes rust-lang#115938. This PR does two things: 1. Unless the `custom_code_classes_in_docs` feature is enabled, it will use the old codeblock tag parser. 2. If there is a codeblock tag that starts with a `.`, it will emit a behaviour change warning. Hopefully this is the last missing part for this feature until stabilization. Follow-up of rust-lang#110800. r? `@notriddle`
Rollup merge of rust-lang#115947 - GuillaumeGomez:custom_code_classes_in_docs-warning, r=notriddle Custom code classes in docs warning Fixes rust-lang#115938. This PR does two things: 1. Unless the `custom_code_classes_in_docs` feature is enabled, it will use the old codeblock tag parser. 2. If there is a codeblock tag that starts with a `.`, it will emit a behaviour change warning. Hopefully this is the last missing part for this feature until stabilization. Follow-up of rust-lang#110800. r? `@notriddle`
Part of #79483.
This is a re-opening of #79454 after a big update/cleanup. I also converted the syntax to pandoc as suggested by @notriddle: the idea is to be as compatible as possible with the existing instead of having our own syntax.
Motivation
From the original issue: #78917
Having custom CSS classes for syntax highlighting will allow tools like
highlight.jsto be used in order to provide highlighting for languages other than Rust while not increasing technical burden on rustdoc.What is the feature about?
In short, this PR changes two things, both related to codeblocks in doc comments in Rust documentation:
language-*CSS classes with thecustomattribute.The
customattributeLet's start with the new
customattribute: it will disable the generation of thelanguage-*CSS class on the generated HTML code block. For example:The generated HTML code block will not have
class="language-c"because thecustomattribute has been set. Thecustomattribute 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.jsorprism.js), allowing to support highlighting for other languages than Rust without increasing burden on rustdoc. To disable the automaticlanguage-*CSS class generation, you need to use thecustomattribute as well.This allow users to write the following:
This will notably produce the following HTML:
Instead of:
To be noted, we could have written
{.language-c}to achieve the same result..andclass=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
unknownfield intoLangString(the parsed code block "attribute") because of cases like this:Without this
unknownfield, 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 theunknownfield 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.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. 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).
Raised concerns
It's not obvious when the
language-*attribute generation will be added or not.It is added by default. If you want to disable it, you will need to use the
customattribute.Why not using HTML in markdown directly then?
Code examples in most languages are likely to contain
<,>,&and"characters. These characters require escaping when written inside the<pre>element. Using the ``` code blocks allows rustdoc to take care of escaping, which means doc authors can paste code samples directly without manually converting them to HTML.cc @poliorcetics
r? @notriddle