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

Fix crate-level docs not being rendered correctly if there is no readme #2726

Merged
merged 3 commits into from
Jan 22, 2025

Conversation

GuillaumeGomez
Copy link
Member

Fixes #2725.

This is an interesting case since there is no README, so instead we tool the crate level docs. But we did a few things wrong:

  • Markdown was not rendered
  • Highlighting wasn't run as expected (it was never picking rust)
  • Lines start were completely trimmed whereas they shouldn't

All fixed in this PR.

@syphar Is there a way to test this except for GUI tests?

 * Markdown was not rendered
 * Highlighting wasn't run as expected
 * Lines start were completely trimmed whereas they shouldn't
@GuillaumeGomez GuillaumeGomez requested a review from a team as a code owner January 17, 2025 21:55
@github-actions github-actions bot added the S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed label Jan 17, 2025
Copy link
Member

@syphar syphar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just some questions for my understanding:

We're (kind of) replicating things that rustdoc already did when generating the docs themselves.

Isn't there any way that we could either reuse the machinery? or is rustdoc so near to normal markdown that we're fine here?

src/db/add_package.rs Show resolved Hide resolved
src/web/highlight.rs Outdated Show resolved Hide resolved
@GuillaumeGomez
Copy link
Member Author

just some questions for my understanding:

We're (kind of) replicating things that rustdoc already did when generating the docs themselves.

Isn't there any way that we could either reuse the machinery? or is rustdoc so near to normal markdown that we're fine here?

Apart from intra-doc links and headings limitations, there is nothing special in rustdoc markdown handling. Also, it's all internal rustdoc code, so unless we write a compiler plugin, we can't access to it. And I don't think it's worth it.

@GuillaumeGomez
Copy link
Member Author

I made the default syntax configurable and optional. Now, if there is a README, it will have the same behaviour as now. However, if it's coming from the crate-level docs because there is no README, it will apply the same rules as rustdoc: if there is no language specified, then by default it's rust.

@syphar
Copy link
Member

syphar commented Jan 22, 2025

@syphar Is there a way to test this except for GUI tests?

@GuillaumeGomez the test you're probably searching for is this one:

fn readme() {
async_wrapper(|env| async move {
env.fake_release()
.await
.name("dummy")
.version("0.1.0")
.readme_only_database("database readme")
.create()
.await?;
env.fake_release()
.await
.name("dummy")
.version("0.2.0")
.readme_only_database("database readme")
.source_file("README.md", b"storage readme")
.create()
.await?;
env.fake_release()
.await
.name("dummy")
.version("0.3.0")
.source_file("README.md", b"storage readme")
.create()
.await?;
env.fake_release()
.await
.name("dummy")
.version("0.4.0")
.readme_only_database("database readme")
.source_file("MEREAD", b"storage meread")
.source_file("Cargo.toml", br#"package.readme = "MEREAD""#)
.create()
.await?;
env.fake_release()
.await
.name("dummy")
.version("0.5.0")
.readme_only_database("database readme")
.source_file("README.md", b"storage readme")
.no_cargo_toml()
.create()
.await?;
let check_readme = |path: String, content: String| {
let env = env.clone();
async move {
let resp = env.web_app().await.get(&path).await.unwrap();
let body = resp.text().await.unwrap();
assert!(body.contains(&content));
}
};
check_readme("/crate/dummy/0.1.0".into(), "database readme".into()).await;
check_readme("/crate/dummy/0.2.0".into(), "storage readme".into()).await;
check_readme("/crate/dummy/0.3.0".into(), "storage readme".into()).await;
check_readme("/crate/dummy/0.4.0".into(), "storage meread".into()).await;
let mut conn = env.async_db().await.async_conn().await;
let details = crate_details(&mut conn, "dummy", "0.5.0", None).await;
assert!(matches!(
details.fetch_readme(&*env.async_storage().await).await,
Ok(None)
));
Ok(())
});
}

You could create a release without readme, but with description_long, that validates if syntax highlighting is added

@syphar syphar requested review from syphar and removed request for syphar January 22, 2025 06:01
@GuillaumeGomez
Copy link
Member Author

Added the regression test. :)

@syphar syphar merged commit 29a0e81 into rust-lang:master Jan 22, 2025
9 checks passed
@github-actions github-actions bot added S-waiting-on-deploy This PR is ready to be merged, but is waiting for an admin to have time to deploy it and removed S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed labels Jan 22, 2025
@GuillaumeGomez GuillaumeGomez deleted the fix-crate-level-docs branch January 22, 2025 14:02
@GuillaumeGomez GuillaumeGomez changed the title Fix crate-level docs not being rendered correctly if there is no readme: Fix crate-level docs not being rendered correctly if there is no readme Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-deploy This PR is ready to be merged, but is waiting for an admin to have time to deploy it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unescaped HTML rendered in /crate page
2 participants