Skip to content

render: fix center image test #3880

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

Merged
merged 1 commit into from
Sep 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,11 @@ mod tests {
#[test]
fn image_alignment() {
let text =
"<img src=\"https://img.shields.io/crates/v/clap.svg\" alt=\"\" align=\"center\">\n";
"<p align=\"center\"><img src=\"https://img.shields.io/crates/v/clap.svg\" alt=\"\"></p>\n";
let result = markdown_to_html(text, None);
assert_eq!(
result,
"<img src=\"https://img.shields.io/crates/v/clap.svg\" alt=\"\" align=\"center\">\n"
"<p align=\"center\"><img src=\"https://img.shields.io/crates/v/clap.svg\" alt=\"\"></p>\n"
Copy link
Member

Choose a reason for hiding this comment

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

aren't these cases already sufficiently tested by the text_alignment test above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The text_alignment test guarantees that the align attribute can be set for <h1> and <h5> HTML tags. By being explicit in this other test, we make sure that centering images will always be supported by catching any possible future regression. Testing is cheap, finding regressions is hard.

Copy link
Member

Choose a reason for hiding this comment

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

shouldn't it be renamed to paragraph_alignment then? I guess the <p> doesn't care whether a <img> is inside or not 😅

Copy link
Contributor Author

@gagath gagath Sep 2, 2021

Choose a reason for hiding this comment

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

You are right that the <p> does not care currently. But maybe in a future release the <p> will care because of implementation changes. The usecase I want to cover is centering images in README.md on crates.io, so I make sure that this particular usecase is tested and will continue to work in the future.

It also as a side effect documents how to center images on crates.io for users.

);
}
}