You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The define_component macro uses a single hash sign # to represent a normal attribute (e.g. #[derive(Debug)]), and uses a double hash sign ## to represent an argument specific to that macro (e.g. ##[min(0.0)]).
I ran cargo doc --document-private-items --open and opened the generated define_component page.
## were replaced by #. (e.g. ##[min(0.0)] became #[min(0.0)])
I think rustdoc should keep code blocks as written (except for coloring, etc.). This is because code blocks are generally expected to be enclosed in the HTML <pre> tag, which defines preformatted text.
In other words, code blocks are preformatted and should be kept as written.
saethlin
added
T-rustdoc
Relevant to the rustdoc team, which will review and decide on the PR/issue.
and removed
needs-triage
This issue may need triage. Remove it if it has been sufficiently triaged.
labels
Nov 18, 2023
It's because you can hide lines of code if you prepend them with #. There is some "intelligence" by using the parser to know when the # is actually used in the code or not. In the current example, the parser doesn't know and rustdoc simply removes it. I don't really see a way to fix it. An idea could be to introduce a new codeblock tag which would allow to say "keep the code as is".
I tried this code:
The
define_component
macro uses a single hash sign#
to represent a normal attribute (e.g.#[derive(Debug)]
), and uses a double hash sign##
to represent an argument specific to that macro (e.g.##[min(0.0)]
).I ran
cargo doc --document-private-items --open
and opened the generateddefine_component
page.I expected to see this happen:
Instead, this happened:
##
were replaced by#
. (e.g.##[min(0.0)]
became#[min(0.0)]
)I think rustdoc should keep code blocks as written (except for coloring, etc.). This is because code blocks are generally expected to be enclosed in the HTML
<pre>
tag, which defines preformatted text.In other words, code blocks are preformatted and should be kept as written.
Perhaps the following code is related:
rust/src/librustdoc/html/markdown.rs
Lines 169 to 172 in 2831701
Workaround
If the doc comment starts with
```text
instead of```
, this problem does not occur.Meta
rustdoc --version --verbose
:The text was updated successfully, but these errors were encountered: