comprehensive-rust
comprehensive-rust copied to clipboard
Make the shell snippets easier to copy/paste (e.g. cargo/running-locally.md)?
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:
- Creating a separate block for the output.
- Removing the dollar sign. This would however make it less obvious that it's a shell command. Unless
mdbookprovides a way to display a dollar sign before the content, but exclude it from the copying?
WDYT?
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.
Glad to see it's already reported upstream :)
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.
Fixed via #951.
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:
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).
Oh alright I could check it out
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:
Update: looks good on WSL though, but not sure why it looks the way it does when serving from windows 🤔
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
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: