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> {
439 MessageType::Emote(content) => content.formatted.as_ref(), 439 MessageType::Emote(content) => content.formatted.as_ref(),
440 MessageType::Notice(content) => content.formatted.as_ref(), 440 MessageType::Notice(content) => content.formatted.as_ref(),
441 441
442 MessageType::Audio(content) => content.formatted.as_ref(), 442 MessageType::Audio(content) => content.formatted_caption(),
443 MessageType::File(content) => content.formatted.as_ref(), 443 MessageType::File(content) => content.formatted_caption(),
444 MessageType::Video(content) => content.formatted.as_ref(), 444 MessageType::Video(content) => content.formatted_caption(),
445 445 MessageType::Image(content) => content.formatted_caption(),
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 },
466 _ => None, 446 _ => None,
467 }; 447 };
468 448
@@ -475,13 +455,20 @@ fn content_html(msgtype: &MessageType) -> Option<StyleTree> {
475 if let Some(filename) = content_filename(msgtype) { 455 if let Some(filename) = content_filename(msgtype) {
476 let html = html.get_or_insert_with(|| { 456 let html = html.get_or_insert_with(|| {
477 let text = body_cow_content(msgtype).into_owned(); 457 let text = body_cow_content(msgtype).into_owned();
478 StyleTree { 458 let text = html::StyleTreeNode::Text(text.into());
479 children: vec![html::StyleTreeNode::Text(text.into())], 459 let text = html::StyleTreeNode::Paragraph(Box::new(text));
480 } 460 StyleTree { children: vec![text] }
481 }); 461 });
482 462
483 html.children.push(html::StyleTreeNode::Break); 463 html.children.insert(0, html::StyleTreeNode::Text(filename.into()));
484 html.children.push(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 }
485 } 472 }
486 473
487 html 474 html