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

Rustdoc does not display a table in some cases involving whitespaces #65802

Closed
dutchmartin opened this issue Oct 25, 2019 · 4 comments
Closed
Assignees
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@dutchmartin
Copy link

When placing a space between the line comment start //! and the start of the table |, the table does not render properly:

//! # Lorem ispum cratus test amet
//!
//!This table has no space between the `//!` and the table start character `|`:
//!
//!| a | s | d | f | g |
//!|---|---|---|---|---|
//!| h | j | k | l | ; |
//!
//! This table has space between the `//!` and the table start character `|`:
//!
//! | a | s | d | f | g |
//! |---|---|---|---|---|
//! | h | j | k | l | ; |
//!

image

If you remove the spaces, it works:

//! # Lorem ispum cratus test amet
//!
//!This table has no space between the `//!` and the table start character `|`:
//!
//!| a | s | d | f | g |
//!|---|---|---|---|---|
//!| h | j | k | l | ; |
//!
//! This table has space between the `//!` and the table start character `|`:
//!
//!| a | s | d | f | g |
//!|---|---|---|---|---|
//!| h | j | k | l | ; |
//!

image

I have made a example repo.
To test this, just clone the repo and run cargo doc --open
I have validated that this bug affects stable, beta and nightly

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Oct 25, 2019
@crlf0710 crlf0710 added the A-rustdoc-ui Area: Rustdoc UI (generated HTML) label Mar 22, 2023
QuantumDancer added a commit to ALU-Schumacher/AUDITOR that referenced this issue Jan 15, 2024
The table was not renderd correctly because of rust-lang/rust#65802
@camelid camelid self-assigned this May 22, 2024
@camelid
Copy link
Member

camelid commented May 22, 2024

The reason this happens is that rustdoc needs to determine what indentation you're using in your doc comments, but you're mixing two different indentation levels, so it picks the smaller of the two (i.e., indent of zero). Thus, no indentation is stripped. Since Markdown doesn't recognize indented tables, the table that has a space before it is rendered wrong. If you instead use a consistent indentation level for each item's (i.e., each function, module, etc.) documentation, you'll see that the issue goes away. In other words, the following renders both tables correctly:

/// # Lorem ispum cratus test amet
///
///This table has no space between the `//!` and the table start character `|`:
///
///| a | s | d | f | g |
///|---|---|---|---|---|
///| h | j | k | l | ; |
///
pub fn foo() {}

/// # Lorem ispum cratus test amet
///
/// This table has space between the `//!` and the table start character `|`:
///
/// | a | s | d | f | g |
/// |---|---|---|---|---|
/// | h | j | k | l | ; |
///
pub fn bar() {}

I'm not sure if rustdoc can necessarily do better than this while respecting that different users may use different indentation levels for their doc comments. It's just like how Python doesn't allow you to mix 2-space and 4-space indentation or tab and space-based indentation in a file; there's no good way to disambiguate.

@camelid
Copy link
Member

camelid commented May 22, 2024

Note that the incorrect table rendering from the commit fed93af that linked to this issue is due to the incorrect double-comment //!//! at https://github.com/ALU-Schumacher/AUDITOR/blob/17aad52176ca0639c08082d981e79a5c2d293b91/auditor/src/lib.rs#L442. That incorrect syntax leads rustdoc to think the overall indentation of the block is zero. It's admittedly unfortunate that it's not obvious that this is the source of the issue.

One possible change we could consider is to base the indentation of the block on only the very first line. We could then report warnings if the indentation were less than that on later lines.

@camelid
Copy link
Member

camelid commented May 22, 2024

Another question is how we handle doc comments like the following

///     fn main() {}
pub fn foo() {}

Do we consider this to be the unindented text fn main() {}, or is it fn main() {} (a code block indented by 4 spaces), or is it fn main() {} (a code block indented by 4 spaces, whose content is in turn indented by 1 space)?

@camelid
Copy link
Member

camelid commented Jul 8, 2024

This was fixed in pulldown-cmark, so this now works correctly as of #127127.

@camelid camelid closed this as completed Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants