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
verbatim_doc_comment should provide ability to escape newlines with \ like in string literals #3198
Comments
Di you see this as different than #2389? |
Yes. That issue was about preserving newlines and This is about escaping newlines away with |
Alternatively, could be the support for |
I missed that, thanks! I went back to try to see why |
Can you try replacing |
Nope, either with |
@pksunkara |
Yup, check the comment I made on that PR. Approach is correct but we need to check for the |
So to double check what you are ultimately trying to accomplish, you are wanting one line to be able to overflow onto following lines and you want another line immediately after it without a paragraph break, right? You originally did this with /// This is a very long line which I'd like to split in code
/// but keep wrapped in terminal {n}
/// This text should be on a new line
... Your thought is to either implement this with /// This is a very long line which I'd like to split in code \
/// but keep wrapped in terminal
/// This text should be on a new line
#[clap(verbatim_doc_comment)]
... or /// This is a very long line which I'd like to split in code
/// but keep wrapped in terminal \n
/// This text should be on a new line
... |
btw something I've been meaning to do is to explore the feature set and API design of other CLI parsers to see what we can learn or to help open us up on the problem space. Click uses escape sequences to customize the help
A key difference is that these are just control codes in a doc string that are probably being ignored by the documentation tools while, as pointed out, Rust doc comments are raw strings so escape sequences are ignored. |
@epage correct. It seems that When talking about other CLI parsers, Python's argparse allows custom help formatting via HelpFormatter class, so maybe clap should externalize help preprocessing as well? There could be 4 functions for |
How is this shown on rust docs? As specified in #2389, our default help text should behave similarly to rust docs. And |
This will be rendered as Okay, another proposal: in markdown we can place slash at the end of line to preserve newline which is opposite to what slash does in Rust str literals (weird!). Although this feature isn't recommended for use and is relatively unknown, it still a part of markdown specification and thus supported by rustdoc, so
Will be rendered by rustdoc as
If we aim to make --help as most close as possible to rustdoc then turning slash followed by newline into |
So, I've implemented that behavior in #3228, let's continue discussion there |
In considering the motivating case for this issue being a regression in functionality in clap3 and the relative size of the various proposed replacements for the clap2 behavior, I'm thinking of restoring |
@I60R can you report back if |
Sorry for being silent. Yes, I like to have |
I want this feature as originally described, but AFAICT currently I either have to use really long lines in the comments with verbatim_doc_comment, or pass it in directly to long_help (i.e. don't use the doc comment functionality). Or I suppose break the line myself, and then if the screen is too narrow, it will wrap weirdly. Alternatively, having a way to toggle between verbatim and non-verbatim mode. I wonder if it would make sense to switch into verbatim mode inside of a code block delimited with triple backticks (and remove those backticks). Or maybe if a line starts with three or more spaces (2 after removing the initial space), then treat it as a new line, and don't remove the initial whitespace? Full markdown support isn't really necessary for me here. |
What do you mean by this? We should only be stripping off a single leading space that would be between the
Except a lot of what you are describing either adds a lot of complexity or is us basically implementing a poor mans version of markdown. A lot of these doc comments people post are because of that gulf; they expect to be able to write markdown and we don't support it. |
I am referring to:
So if verbatim_doc_comment is true, you lose any indentation at the beginning of the line. Initially, I didn't think there was any way to get that back, but actually I did figure out a way to do it. If I put "{n}" at the beginning of the line, then put the space between that and the text of the line, the whitespace is preserved.
No, not really. My example isn't even really markdown. It looks something like:
If I were to write that in markdown, I suppose I could put the examples inside triple backquotes. Would that be included in the scope of the markdown support feature? But as is, it isn't really markdown, just text with some indentation. And it really doesn't need things like headers, emphasis, links, etc. (although such things certainly could be useful in general). |
Ah, I had missed the trim on non-verbatim lines. That seems odd that we trim leading whitespace. In general
This leads to us supporting markdown, even if its not the most thorough parser. This is why I created md-rosetta-rs was to look for the cheapest parser that gets things done.
I strongly expect headers will be needed. While we are talking about doc comments, I expect people will want to write markdown for others parts as well and we should consider how we can support that for people. |
Please complete the following tasks
Rust Version
Clap Version
3.0.0.rc7
Minimal reproducible code
Steps to reproduce the bug with the above code
Actual Behaviour
This is a very long line which I'd like to split in code \
but keep wrapped in terminal
This text should be on a new line
Expected Behaviour
This is a very long line which I'd like to split in code but keep wrapped in terminal
This text should be on a new line
Additional Context
Previously
{n}
allowed to achieve the expected effectDebug Output
No response
The text was updated successfully, but these errors were encountered: