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: item summaries that are headers are not printed in module pages, under hoedown #46377

Closed
QuietMisdreavus opened this issue Nov 29, 2017 · 1 comment · Fixed by #46387
Assignees
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@QuietMisdreavus
Copy link
Member

/// # Check out this struct!
pub struct SomeStruct;

This will show up differently in docs depending on whether Hoedown or Pulldown is being used. It's not a rendering difference for the markdown, per se, it's how the summary line is generated:

fn shorter<'a>(s: Option<&'a str>) -> String {
    match s {
        Some(s) => s.lines().take_while(|line|{
            (*line).chars().any(|chr|{
                !chr.is_whitespace()
            })
        }).collect::<Vec<_>>().join("\n"),
        None => "".to_string()
    }
}

That function is used to truncate markdown renderings from Hoedown for summary lines on module pages. Hoedown (presumably) emits an extra blank line before the <h1> in this sample, so this shorter function immediately sees a blank line and emits an empty string.

A fix for this could just add a skip_while(|s| s.chars().all(|c| c.is_whitespace())) before the take_while there, which would skip all empty/blank lines before the first block of text, and thus properly grab the first item from the block.

(Note: the reason this actually emits the header in Pulldown is that under Pulldown, shorter is not actually called! It goes through a separate adapter that wraps the event emitter from Pulldown and stops once the first block is complete. This way it skips the leading-whitespace problem entirely.)

@QuietMisdreavus QuietMisdreavus added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools labels Nov 29, 2017
@QuietMisdreavus QuietMisdreavus self-assigned this Nov 29, 2017
@QuietMisdreavus
Copy link
Member Author

(Also, this fix is not completely useless after the Pulldown switch is over, since plain_summary_line also calls this to truncate the input markdown for a Pulldown render pass, and that's called more broadly.)

kennytm added a commit to kennytm/rust that referenced this issue Dec 1, 2017
Fix rustdoc item summaries that are headers

Rustoc item summaries that are headers were not displayed at all because
they started with whitespace.

This PR fixes this and now removes the whitespace and then displays the
block.

I'm not sure if the rustdoc test is written correctly, if there's anything to improve, just let me know. :)

This fixes rust-lang#46377.

This is how it looks when rendered out now:
![Rendered](https://i.imgur.com/7u8jUAM.png)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant