Skip to content

[Feature Request] Skip formatting doc comments altogether when mixing sugared and de-sugared doc comments #6017

Open
@stepancheg

Description

@stepancheg

Input:

//! <details open>
//!     <summary>Example 1</summary>
//!
//! ```
#![doc = "test()"]
//! ```
//!
//! </details>
//!
//! <details open>
//!     <summary>Example 2</summary>
//!
//! ```
//! example(2);
//! ```
//!
//! </details>
rustfmt +nightly --config format_code_in_doc_comments=true

Outputs:

//! <details open>
//!     <summary>Example 1</summary>
//!
//! ```
#![doc = "test()"]
//! ```
//!
//! </details>
//!
//! <details open>
//!     <summary>Example 2</summary>
//! ```
//! example(2);
//! ```
//!
//! </details>

Note no empty line before second example. So rustdoc of output looks like this:

image

Empty lines before backticks are important for Markdown.

Rustdoc uses commonmark

HTML blocks in commonmark must end with empty line:

End condition: line is followed by a blank line

rustfmt 1.7.0-nightly (ca663b06 2024-01-08)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions