From 76e163098bf15a5f1648ffb0f0b331e4eb8f4f58 Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Fri, 2 Jan 2026 05:27:18 +0300 Subject: [PATCH] feat(post_parser): support show caption above media attribute for message rendering Add support for Telegram's show_caption_above_media message attribute to conditionally order caption and media content in HTML output. When enabled, media is rendered before the text caption instead of the default text-before-media order. --- post_parser.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/post_parser.py b/post_parser.py index 4975577..07d6a21 100644 --- a/post_parser.py +++ b/post_parser.py @@ -490,6 +490,7 @@ class PostParser: 'reactions': self._extract_reactions(message), 'media_group_id': message.media_group_id, 'service': getattr(message, "service", None), + 'show_caption_above_media': getattr(message, 'show_caption_above_media', False), 'raw_message': str(message) } @@ -604,18 +605,29 @@ class PostParser: media_html = self._generate_html_media(message) content_body.append(f'
') - if forward_html: + if forward_html: content_body.append(forward_html) # Forward info content_body.append("
") - if reply_html: + if reply_html: content_body.append(reply_html) # Reply info content_body.append("
") - if text_html: - content_body.append(text_html) # Post text - content_body.append("
") + + show_caption_above = getattr(message, 'show_caption_above_media', False) - content_body.append(media_html) # Media - content_body.append("
") + if show_caption_above: + if media_html: + content_body.append(media_html) + content_body.append("
") + if text_html: + content_body.append(text_html) + content_body.append("
") + else: + if text_html: + content_body.append(text_html) + content_body.append("
") + if media_html: + content_body.append(media_html) + content_body.append("
") if poll_html: content_body.append(poll_html) # Poll if message.forward_origin: content_body.append(f"--- Forwarded post end ---") # Forward info end