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

doc test parsing/displaying #5053

Closed
2 tasks done
djugei opened this issue Jul 30, 2023 · 3 comments
Closed
2 tasks done

doc test parsing/displaying #5053

djugei opened this issue Jul 30, 2023 · 3 comments
Labels
C-bug Category: Updating dependencies

Comments

@djugei
Copy link

djugei commented Jul 30, 2023

Please complete the following tasks

Rust Version

rustc 1.73.0-nightly (8771282d4 2023-07-23)

Clap Version

4.3.19

Minimal reproducible code

/// short
///
/// ```bash
/// $ echo hi
/// $ echo ih
/// ```
#[command(version, about)]
struct Command;

Steps to reproduce the bug with the above code

cargo run -- --help

Actual Behaviour

puts the whole code block on one line, and includes ```bash and ``` in output

Expected Behaviour

puts each line in the code block on its own line, strips the ```bash and ```, possibly specially formats/highlights the code.

Additional Context

using verbatim_doc_comment solves half of this issue

somewhat similar to #2389

sidenote: clap version can not be found with grep clap Cargo.lock as instructed in the bug report form

grep 'name = "clap"' Cargo.lock -C1

works

Debug Output

No response

@djugei djugei added the C-bug Category: Updating dependencies label Jul 30, 2023
@epage
Copy link
Member

epage commented Jul 31, 2023

How would you describe this as different than #2389? I'm inclined to close in favor of #2389

@djugei
Copy link
Author

djugei commented Aug 1, 2023

#2389 (comment) mentions fenced code blocks, so i somewhat agree (even though i disagree with most of the later suggestions of that specific comment). i simply did not find that part of the discussion when searching for doc test or code example.

as for differences: this is a subset of the full markdown spec that could be implemented without doing the entire thing, so if that is a direction you are interested in pursuing its different, if you intend to have full markdown support then, as i said, its just a subset of that.

i don't know how the actual code is structured, and it would need to check for a backspace in front of ``` too, but basically this does the trick:

let mut strip_newlines = true;
lines.map(|line| {
if line.contains("```") {strip_newlines = !strip_newlines}; (strip_newlines, line)
})
.do_the_strip
.filter(|(_, line)| !line.contains("```")

@epage
Copy link
Member

epage commented Aug 1, 2023

For another project, I've written a code-fence subset of a markdown parser. The overall need is bigger than that in terms of we need to correctly parse hard vs soft newlines. For that, we should use a more general parser than picking at this problem a piece a time.

Closing in favor of #2389

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Updating dependencies
Projects
None yet
Development

No branches or pull requests

2 participants