Skip to content

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

Closed
@max-heller

Description

@max-heller

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-Code-BlocksArea: Code blocksC-bugCategory: A bug, incorrect or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions