Skip to content

Commit 6eea612

Browse files
committed
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.
1 parent d04dc22 commit 6eea612

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/render.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ mod tests {
391391
let absolute = "[hi](/hi)";
392392
let relative = "[there](there)";
393393
let image = "![alt](img.png)";
394+
let html_image = "<img src=\"img.png\" alt=\"alt\">";
394395
let svg = "![alt](sanitize.svg)";
395396

396397
for host in &["github.com", "gitlab.com", "bitbucket.org"] {
@@ -429,6 +430,15 @@ mod tests {
429430
)
430431
);
431432

433+
let result = markdown_to_html(html_image, Some(&url));
434+
assert_eq!(
435+
result,
436+
format!(
437+
"<img src=\"https://{}/rust-lang/test/raw/HEAD/img.png\" alt=\"alt\">\n",
438+
host
439+
)
440+
);
441+
432442
let result = markdown_to_html(svg, Some(&url));
433443
assert_eq!(
434444
result,
@@ -520,4 +530,15 @@ mod tests {
520530
"<h1 align=\"center\">foo-bar</h1>\n<h5 align=\"center\">Hello World!</h5>\n"
521531
);
522532
}
533+
534+
#[test]
535+
fn image_alignment() {
536+
let text =
537+
"<img src=\"https://img.shields.io/crates/v/clap.svg\" alt=\"\" align=\"center\">\n";
538+
let result = markdown_to_html(text, None);
539+
assert_eq!(
540+
result,
541+
"<img src=\"https://img.shields.io/crates/v/clap.svg\" alt=\"\" align=\"center\">\n"
542+
);
543+
}
523544
}

0 commit comments

Comments
 (0)