Skip to content

rustdoc enhancement: indent all lines by 4 spaces in the playground #39947

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

Closed
Wilfred opened this issue Feb 19, 2017 · 3 comments
Closed

rustdoc enhancement: indent all lines by 4 spaces in the playground #39947

Wilfred opened this issue Feb 19, 2017 · 3 comments

Comments

@Wilfred
Copy link
Contributor

Wilfred commented Feb 19, 2017

For example, https://doc.rust-lang.org/std/env/fn.args.html includes the following code sample:

use std::env;

// Prints each argument on a separate line
for argument in env::args() {
    println!("{}", argument);
}

However, the run button produces this URL:

https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Aenv%3B%0A%0A%2F%2F%20Prints%20each%20argument%20on%20a%20separate%20line%0Afor%20argument%20in%20env%3A%3Aargs()%20%7B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20argument)%3B%0A%7D%0A%7D

which gives the following code in the playground:

fn main() {
use std::env;

// Prints each argument on a separate line
for argument in env::args() {
    println!("{}", argument);
}
}

This is a papercut: could we just indent all lines by four spaces? Ideally we'd show the code in the playground with indentation that looks pretty similar to code in a full program.

An alternative option would be to run rustfmt when code is sent to the playground. This risks changing the formatting of the example, which potentially surprising to readers. The advantage of this is that it works with multiline string literals too:

// indenting every line by 4 spaces here would change the value oft he string
let x = "
";
@frewsxcv
Copy link
Member

This looks like a duplicate of #35483. Thanks for filing though!

@Wilfred
Copy link
Contributor Author

Wilfred commented Feb 19, 2017

Argh, I missed it. Sorry for the noise. @frewsxcv would you mind correcting the spelling in the title of #35483?

@frewsxcv
Copy link
Member

@Wilfred Ah, good catch, fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants