Commit f8e9b9d62f

f8e9b9d62f9051a3d0f32cbd3270a066dd860108

parent: 72c40b4e46

Unregistered key

vaw <git@nlih.de> · 2026-11-21 13:42 UTC
committer: <noreply@github.com>

Fix non html image caption (#869)

Layout: unified · split

src/message/mod.rs +16 −29
@@ -439,30 +439,10 @@ fn content_html(msgtype: &MessageType) -> Option<StyleTree> {
439439 MessageType::Emote(content) => content.formatted.as_ref(),
440440 MessageType::Notice(content) => content.formatted.as_ref(),
441441
442 MessageType::Audio(content) => content.formatted.as_ref(),
443 MessageType::File(content) => content.formatted.as_ref(),
444 MessageType::Video(content) => content.formatted.as_ref(),
445
446 MessageType::Image(content) => {
447 let mut html = if let Some(FormattedBody { format: MessageFormat::Html, body }) =
448 &content.formatted
449 {
450 parse_matrix_html(body.as_str())
451 } else {
452 StyleTree { children: vec![] }
453 };
454
455 html.children
456 .insert(0, html::StyleTreeNode::Text(display_file_name!(Image, content).into()));
457
458 let src = content.source.clone();
459 html.children.insert(
460 0,
461 html::StyleTreeNode::Image(html::Image::new(src, content.info.as_deref())),
462 );
463
464 return Some(html);
465 },
442 MessageType::Audio(content) => content.formatted_caption(),
443 MessageType::File(content) => content.formatted_caption(),
444 MessageType::Video(content) => content.formatted_caption(),
445 MessageType::Image(content) => content.formatted_caption(),
466446 _ => None,
467447 };
468448
@@ -475,13 +455,20 @@ fn content_html(msgtype: &MessageType) -> Option<StyleTree> {
475455 if let Some(filename) = content_filename(msgtype) {
476456 let html = html.get_or_insert_with(|| {
477457 let text = body_cow_content(msgtype).into_owned();
478 StyleTree {
479 children: vec![html::StyleTreeNode::Text(text.into())],
480 }
458 let text = html::StyleTreeNode::Text(text.into());
459 let text = html::StyleTreeNode::Paragraph(Box::new(text));
460 StyleTree { children: vec![text] }
481461 });
482462
483 html.children.push(html::StyleTreeNode::Break);
484 html.children.push(html::StyleTreeNode::Text(filename.into()));
463 html.children.insert(0, html::StyleTreeNode::Text(filename.into()));
464
465 if let MessageType::Image(content) = msgtype {
466 let src = content.source.clone();
467 html.children.insert(
468 0,
469 html::StyleTreeNode::Image(html::Image::new(src, content.info.as_deref())),
470 );
471 }
485472 }
486473
487474 html