Add alt and title to markdown images

This commit is contained in:
Héctor Ramón Jiménez 2025-02-04 20:18:49 +01:00
parent a6e64eac6f
commit 387abafa3a
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 31 additions and 17 deletions

View file

@ -195,7 +195,7 @@ impl Markdown {
let preview = markdown::view_with(
self.content.items(),
&self.theme,
&MarkdownViewer {
&CustomViewer {
images: &self.images,
now: self.now,
},
@ -251,12 +251,12 @@ impl Markdown {
}
}
struct MarkdownViewer<'a> {
struct CustomViewer<'a> {
images: &'a HashMap<markdown::Url, Image>,
now: Instant,
}
impl<'a> markdown::Viewer<'a, Message> for MarkdownViewer<'a> {
impl<'a> markdown::Viewer<'a, Message> for CustomViewer<'a> {
fn on_link_clicked(url: markdown::Url) -> Message {
Message::LinkClicked(url)
}
@ -264,8 +264,9 @@ impl<'a> markdown::Viewer<'a, Message> for MarkdownViewer<'a> {
fn image(
&self,
_settings: markdown::Settings,
_title: &markdown::Text,
url: &'a markdown::Url,
_title: &'a str,
_alt: &markdown::Text,
) -> Element<'a, Message> {
if let Some(Image::Ready { handle, fade_in }) = self.images.get(url) {
center_x(