Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
markdown: Include the message's has_* attributes in render result.
PieterCK1cbf4f1067dd
diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.pyindex 59f1028c7a9..84939dab0fe 100644--- a/zerver/lib/markdown/__init__.py+++ b/zerver/lib/markdown/__init__.py@@ -123,6 +123,8 @@ class MessageRenderingResult:user_ids_with_alert_words: set[int]potential_attachment_path_ids: list[str]thumbnail_spinners: set[str]+ has_image: bool+ has_link: bool@dataclass@@ -635,8 +637,8 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor):desc = desc if desc is not None else ""# Update message.has_image attribute.- if "message_inline_image" in class_attr and self.zmd.zulip_message:- self.zmd.zulip_message.has_image = True+ if "message_inline_image" in class_attr:+ self.zmd.zulip_rendering_result.has_image = Trueif insertion_index is not None:div = Element("div")@@ -1098,8 +1100,8 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor):}# Update message.has_link attribute.- if len(found_urls) > 0 and self.zmd.zulip_message:- self.zmd.zulip_message.has_link = True+ if len(found_urls) > 0:+ self.zmd.zulip_rendering_result.has_link = Trueif self.zmd.zulip_message:for url in unique_urls:@@ -2186,8 +2188,7 @@ class ImageInlineProcessor(markdown.inlinepatterns.ImageInlineProcessor):)# Update message.has_image attribute.- if self.zmd.zulip_message:- self.zmd.zulip_message.has_image = True+ self.zmd.zulip_rendering_result.has_image = Truereturn img@@ -2635,16 +2636,10 @@ def do_convert(user_ids_with_alert_words=set(),potential_attachment_path_ids=[],thumbnail_spinners=set(),+ has_image=False,+ has_link=False,)- # Set has_image and has_link attributes on message to False before- # converting to Markdown each time a message's content is processed.- # This way if a message's content is edited these attributes are- # checked and set to True when the updated content is processed.- if message is not None:- message.has_image = False- message.has_link = False-md_engine.zulip_message = messagemd_engine.zulip_rendering_result = rendering_resultmd_engine.zulip_realm = message_realm@@ -2718,6 +2713,12 @@ def do_convert(if content_with_thumbnails is not None:rendering_result.rendered_content = content_with_thumbnails+ # Update the has_link and has_image on message based on the rendering result.+ # This way if a message's content is edited these attributes are still accurate.+ if message is not None:+ message.has_image = rendering_result.has_image+ message.has_link = rendering_result.has_link+# Throw an exception if the content is huge; this protects the# rest of the codebase from any bugs where we end up rendering# something huge.