Skip to content

rustdoc: Strip empty line(s) above and/or below hidden code in Rust code blocks #48383

@Havvy

Description

@Havvy

Consider the following code:

//! Top-level documentation.
//!
//! ```rust
//! // ... some Rust code ...
//!
//! # // ... hidden boilerplate-y Rust code ...
//!
//! // ... some Rust code ...
//! ```

Currently (last checked: 2024), rustdoc renders two empty lines in between the first & the last comment (quite reasonably so). However, it might be nice to essentially collapse them into a single line since the author likely didn't intend to have extra lines in the rendered output but only in the source code for legibility (since there the #-prefixed code is obviously visible).

The "workaround" / user fix for this is to manually hide the "blank" lines with #:

//! Top-level documentation.
//!
//! ```rust
//! // ... some Rust code ...
//! #
//! # // ... hidden boilerplate-y Rust code ...
//!
//! // ... some Rust code ...
//! ```

An argument could be made that this is less "esthetically pleasing" and a bit annoying.

Original issue description from 2018 for context

Basically, I want:

rust code

# secret boilerplatey rust code

more rust code

to render the same as:

rust code
#
# secret boilerplatey rust code

more rust code

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-rustdoc-uiArea: Rustdoc UI (generated HTML)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.T-rustdoc-frontendRelevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions