Skip to content

Commit

Permalink
Auto merge of #3862 - MicroJoe:align-image-tests, r=Turbo87
Browse files Browse the repository at this point in the history
render: add HTML image tests with align support

I was not sure that the `align` properly was supported for images, so I extended the `render.rs` tests to convince me that it indeed worked as intended.

Below is the commit message:

```
render: add HTML image tests with align support

The current align test was only used for text, but we want to be sure
that images can be aligned too. This is why a new test is added to
verify that the align attribute is also kept for images.

Since the align attribute requires RAW HTML for the <img> tag, the
relative_links test has also been updated to check for this usage.
```
  • Loading branch information
bors committed Aug 24, 2021
2 parents d04dc22 + 6eea612 commit 20e1fe7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ mod tests {
let absolute = "[hi](/hi)";
let relative = "[there](there)";
let image = "![alt](img.png)";
let html_image = "<img src=\"img.png\" alt=\"alt\">";
let svg = "![alt](sanitize.svg)";

for host in &["github.com", "gitlab.com", "bitbucket.org"] {
Expand Down Expand Up @@ -429,6 +430,15 @@ mod tests {
)
);

let result = markdown_to_html(html_image, Some(&url));
assert_eq!(
result,
format!(
"<img src=\"https://{}/rust-lang/test/raw/HEAD/img.png\" alt=\"alt\">\n",
host
)
);

let result = markdown_to_html(svg, Some(&url));
assert_eq!(
result,
Expand Down Expand Up @@ -520,4 +530,15 @@ mod tests {
"<h1 align=\"center\">foo-bar</h1>\n<h5 align=\"center\">Hello World!</h5>\n"
);
}

#[test]
fn image_alignment() {
let text =
"<img src=\"https://img.shields.io/crates/v/clap.svg\" alt=\"\" align=\"center\">\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"
);
}
}

0 comments on commit 20e1fe7

Please sign in to comment.