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

Line hiding in Rust code blocks is inconsistent with rustdoc #2526

Open
max-heller opened this issue Jan 18, 2025 · 1 comment · May be fixed by #2530
Open

Line hiding in Rust code blocks is inconsistent with rustdoc #2526

max-heller opened this issue Jan 18, 2025 · 1 comment · May be fixed by #2530
Labels
A-Code-Blocks Area: Code blocks C-bug Category: A bug, incorrect or unintended behavior

Comments

@max-heller
Copy link
Contributor

Problem

Lines in Rust code blocks beginning with a # and followed immediately by a character other than !, [, #, or are hidden by mdbook but shown by rustdoc.

For example, the following code block is rendered as empty by mdbook:

```rust
#fn main() {}
```

Meanwhile, the following code block in a doc comment:

/// ```
/// #fn main() {}
/// ```
pub struct Foo;

is rendered as
Image

Steps

  1. mdbook init
  2. echo '```rust\n#fn main() {}\n```' > src/chapter_1.md
  3. mdbook serve
  4. Observe an empty code block. When the "Show hidden lines" button is clicked, the code block contains fn main() {}

Possible Solution(s)

mdbook should implement rustdoc's behavior since the docs claim it does:

For the Rust language, you can use the # character as a prefix which will hide lines like you would with Rustdoc.

Notes

rustdoc's rules are:

  • If a line begins with # (note the space following the #), the line is hidden
  • Two consecutive hashes ## can be used to prevent the hiding of a line that would otherwise be hidden
    • To write a non-hidden line that starts with # , write ## which will render as #

Is mdbook willing to change this in a non-breaking release since it seems like a bug according to the docs, or would you rather wait until 0.5?

Version

mdbook v0.4.43
@max-heller max-heller added the C-bug Category: A bug, incorrect or unintended behavior label Jan 18, 2025
@max-heller max-heller changed the title Line hiding in Rust code blocks is inconsistent with `rustdoc1 Line hiding in Rust code blocks is inconsistent with rustdoc Jan 18, 2025
@ehuss ehuss added the A-Code-Blocks Area: Code blocks label Jan 20, 2025
@ehuss
Copy link
Contributor

ehuss commented Jan 20, 2025

Yea, I'd like to see a PR synchronizing with rustdoc's rules.

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 C-bug Category: A bug, incorrect or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants