html: add alt text support for images

This commit is contained in:
xfnw 2024-04-09 11:31:29 -04:00
parent 40b0cae06e
commit f859437560
1 changed files with 10 additions and 3 deletions

View File

@ -74,9 +74,16 @@ impl Traverser for Handler {
};
if link.is_image() {
// FIXME: needs alt text support
self.0
.push_str(format!("<img src=\"{}\">", HtmlEscape(&path)));
if let Some(Some(caption)) = link.caption().map(|c| c.value()) {
self.0.push_str(format!(
r#"<img src="{}" alt="{}">"#,
HtmlEscape(&path),
HtmlEscape(caption.trim())
));
} else {
self.0
.push_str(format!("<img src=\"{}\">", HtmlEscape(&path)));
}
return ctx.skip();
}