From f859437560faf4ca72503a46b60da4ec10778ebc Mon Sep 17 00:00:00 2001 From: xfnw Date: Tue, 9 Apr 2024 11:31:29 -0400 Subject: [PATCH] html: add alt text support for images --- src/html.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/html.rs b/src/html.rs index d06cfe8..d1d0350 100644 --- a/src/html.rs +++ b/src/html.rs @@ -74,9 +74,16 @@ impl Traverser for Handler { }; if link.is_image() { - // FIXME: needs alt text support - self.0 - .push_str(format!("", HtmlEscape(&path))); + if let Some(Some(caption)) = link.caption().map(|c| c.value()) { + self.0.push_str(format!( + r#"{}"#, + HtmlEscape(&path), + HtmlEscape(caption.trim()) + )); + } else { + self.0 + .push_str(format!("", HtmlEscape(&path))); + } return ctx.skip(); }