comprehensive-rust icon indicating copy to clipboard operation
comprehensive-rust copied to clipboard

Make the shell snippets easier to copy/paste (e.g. cargo/running-locally.md)?

Open gendx opened this issue 2 years ago • 3 comments

The code blocks of mdbook provide a "Copy to clipboard" button - however pages like https://google.github.io/comprehensive-rust/cargo/running-locally.html contain shell blocks like follows:

$ cargo new exercise
     Created binary (application) `exercise` package

Clicking copies the whole block, including the dollar sign and the shell output. It would be nice to be able to only copy the command, e.g. cargo new exercise. We could achieve that by:

  1. Creating a separate block for the output.
  2. Removing the dollar sign. This would however make it less obvious that it's a shell command. Unless mdbook provides a way to display a dollar sign before the content, but exclude it from the copying?

WDYT?

gendx avatar Feb 03 '23 13:02 gendx

Yeah, that's definitely an annoyance. It's reported upstream here: https://github.com/rust-lang/mdBook/issues/864.

People tried to fix it repeatedly: https://github.com/google/comprehensive-rust/pull/25 and https://github.com/google/comprehensive-rust/pull/29. So we should probably do something about it...

My idea would be to fix it upstream, but I haven't taken the time to do that.

mgeisler avatar Feb 03 '23 16:02 mgeisler

Glad to see it's already reported upstream :)

gendx avatar Feb 03 '23 16:02 gendx

Our style guide actually talks about this: https://developers.google.com/style/code-syntax#prompt.

The system used there knows to not copy the $, even for examples that contain multiple commands. I think we should enhance mdbook with a similar capability.

mgeisler avatar Feb 04 '23 09:02 mgeisler

Fixed via #951.

mgeisler avatar Jul 11 '23 06:07 mgeisler

If mdbook ever gets support for not copying the prompt, then we can consider adding the prompts back. For now, it's probably better to remove them since this has been suggested repeatedly :smile:

mgeisler avatar Jul 11 '23 06:07 mgeisler

Hi @sharunkumar, thanks for tackling this. There is a final place where we have a $ infront of the shell commands: build_all.sh. These dollar signs show up in the Android section.

We should fix those too to make things consistent. Right now, we include the commands from the shell script and hard-code the output. So the Markdown on the page linked above looks like this:

```shell
{{#include ../build_all.sh:hello_rust}}
Hello from Rust!
```

We could separate the output from the shell commands (like you did in your PRs).

mgeisler avatar Jul 11 '23 07:07 mgeisler

Oh alright I could check it out

sharunkumar avatar Jul 11 '23 21:07 sharunkumar

Idk if its because I'm running it from windows but when I run mdbook serve this is what that page looks like on localhost, after the changes:

image

Update: looks good on WSL though, but not sure why it looks the way it does when serving from windows 🤔

sharunkumar avatar Jul 11 '23 21:07 sharunkumar

We could separate the output from the shell commands (like you did in your PRs)

@mgeisler when doing this, the test build fails on the PR

I noticed this when I tried it in the previous PR itself, ~not sure how to fix it~

Update: figured it out, had to specify the language for the new code block

sharunkumar avatar Jul 11 '23 22:07 sharunkumar

We could separate the output from the shell commands (like you did in your PRs)

@mgeisler when doing this, the test build fails on the PR

I noticed this when I tried it in the previous PR itself, ~not sure how to fix it~

Update: figured it out, had to specify the language for the new code block

Great that you figured it out — the error looks very mysterious at first! :smile:

mgeisler avatar Jul 12 '23 09:07 mgeisler