Skip to content
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

No way to not comment a line beginning with a # in rustdoc #41783

Closed
jFransham opened this issue May 6, 2017 · 4 comments
Closed

No way to not comment a line beginning with a # in rustdoc #41783

jFransham opened this issue May 6, 2017 · 4 comments
Assignees
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@jFransham
Copy link
Contributor

I have a doctest in my shell_parse crate that includes a shell-style comment at the start of a line, inside a code block. Minimal example:

/// ```rust
/// let test_string = r#"
/// # Help me
/// "#;
/// ```

This causes the hash to be stripped out in cargo doc output (which is annoying, because it's part of the example), and causes the parsing to fail and the doctest to fail as a result. Using the same code in a normal test does not fail, and replacing the # with ## causes it to appear in documentation output and the test to succeed. This is the approach I've taken as a workaround, but it's not what I actually want.

@Mark-Simulacrum
Copy link
Member

This behavior is actually intentional. rustdoc strips out lines that begin with # to make it easier to write partial examples (e.g., without showing fn main or helper functions that were perhaps shown in examples given before the current one). Does that make sense?

@jFransham
Copy link
Contributor Author

Ok, but there doesn't seem to be a way to intentionally include lines beginning with a single hash, either with ## or with \#, both interpolate that literal string into the output.

@Mark-Simulacrum Mark-Simulacrum changed the title Hashes in rustdoc code samples leads to strange behaviour No way to not comment a line beginning with a # in rustdoc May 6, 2017
@Mark-Simulacrum Mark-Simulacrum self-assigned this May 6, 2017
@Mark-Simulacrum Mark-Simulacrum added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label May 6, 2017
@Mark-Simulacrum
Copy link
Member

Okay, I've put up a fix with ## as the method for de-commenting lines: #41785.

@jFransham
Copy link
Contributor Author

That's a great fix, thanks a lot.

bors added a commit that referenced this issue May 7, 2017
Allow # to appear in rustdoc code output.

"##" at the start of a trimmed rustdoc line is now cut to "#" and then
shown. If the user wanted to show "##", they can type "###".

I'm somewhat concerned about the potential implications for users, since this does make a potentially backwards-incompatible change. Previously, `##` had no special handling, and now we do change it. However, I'm not really sure what we can do here to improve this, and I can't think of any cases where `##` would likely be correct in a code block, though of course I could be wrong.

Fixes #41783.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants