Skip to content

Stray spacing of code blocks containing injected main #1433

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
dtolnay opened this issue Jan 6, 2021 · 6 comments · Fixed by #1806
Closed

Stray spacing of code blocks containing injected main #1433

dtolnay opened this issue Jan 6, 2021 · 6 comments · Fixed by #1806
Labels
A-Code-Blocks Area: Code blocks A-Style Area: Style (CSS, etc.)

Comments

@dtolnay
Copy link
Member

dtolnay commented Jan 6, 2021

For example see the first code block in https://doc.rust-lang.org/1.47.0/book/ch03-02-data-types.html.

```rust
let guess: u32 = "42".parse().expect("Not a number!");
```

Screenshot:

Screenshot from 2020-11-05 21-31-53

@dtolnay
Copy link
Member Author

dtolnay commented Jan 6, 2021

Desired:

Screenshot from 2020-11-05 21-32-20


#1374 has one fix, but it isn't perfect because a long first line on a narrow screen can cause the buttons to overlap the code when they didn't before. (There is a separate bug about this: #1322.)

@pickfire
Copy link
Contributor

pickfire commented Jan 7, 2021

But I see that mdbook examples itself does not have the extra spacing.

image

@pickfire
Copy link
Contributor

pickfire commented Jan 7, 2021

Oh, the newline only appears on some block.

Screen Shot 2021-01-07 at 10 47 32

What if we put it the buttons closer to the borders on mobile? So even if it did overlap, it overlap half of it.

Or maybe we can put the buttons outside of the box in mobile.

Screen Shot 2021-01-07 at 10 50 23

@dtolnay
Copy link
Member Author

dtolnay commented Jan 7, 2021

But I see that mdbook examples itself does not have the extra spacing.

Correct. That code block does not have an injected main. The main is handwritten.

```rust
# fn main() {
let x = 5;
let y = 7;
println!("{}", x + y);
# }
```

@ehuss
Copy link
Contributor

ehuss commented May 17, 2022

I posted #1806 with a proposed fix.

I would appreciate if you could take a look and see if you have any thoughts. I posted a demo at https://ehuss.github.io/rust-book/. If you could look through some examples, try different browsers and platforms, different color themes, etc. If you have access to Android, that would particularly be nice to test since I don't have access to that.

@dtolnay
Copy link
Member Author

dtolnay commented May 17, 2022

Android/Firefox:

Chrome looks substantially identical.

The non-editable code blocks look passable to me, certainly better than before your change. The editable ones are not getting the same padding and are not so good I think.

What if we offset the icons by half a line upwards, so that they are half in/half out of the box? Then we could get away with less padding on those non-editable code blocks, since I think I'd prefer less than what's in the screenshot. If half in/half out looks janky, they could get either a tab (background extending up in the vicinity of the icons) or notch (background carved downward away from the vicinity of the icons).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Code-Blocks Area: Code blocks A-Style Area: Style (CSS, etc.)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants