Skip to content

Commit

Permalink
render: add HTML image tests with align support
Browse files Browse the repository at this point in the history
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
gagath committed Aug 24, 2021
1 parent d04dc22 commit 6eea612
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 6eea612

Please sign in to comment.