Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

import_util: Refactor a `get_markdown_image_for_url`.

PieterCK2fc1bf8d9b47
diff --git a/zerver/data_import/microsoft_teams.py b/zerver/data_import/microsoft_teams.py
index 859899540bc..83c7db662bb 100644
--- a/zerver/data_import/microsoft_teams.py
+++ b/zerver/data_import/microsoft_teams.py
@@ -38,7 +38,7 @@ from zerver.data_import.import_util import (
)
from zerver.data_import.sequencer import NEXT_ID
from zerver.lib.export import MESSAGE_BATCH_CHUNK_SIZE, do_common_export_processes
-from zerver.lib.markdown import get_markdown_link_for_url
+from zerver.lib.markdown import get_markdown_image_for_url
from zerver.lib.mime_types import bare_content_type
from zerver.lib.parallel import run_parallel_queue
from zerver.lib.partial import partial
@@ -546,7 +546,7 @@ def process_hosted_content_attachments(
)
# Use inline thumbnail here since MS Teams only supports customizing the hosted
# content image's alt tag.
- return get_markdown_link_for_url(file_name, attachment_data.url, inline_thumbnail=True)
+ return get_markdown_image_for_url(file_name, attachment_data.url)
if is_direct_message_type:
# TODO: hosted content URL for private chats have a different format, we
diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.py
index 39a8d471bfc..59f1028c7a9 100644
--- a/zerver/lib/markdown/__init__.py
+++ b/zerver/lib/markdown/__init__.py
@@ -2832,12 +2832,13 @@ def render_message_markdown(
return rendering_result
-def get_markdown_link_for_url(filename: str, url: str, inline_thumbnail: bool = False) -> str:
+def get_markdown_link_for_url(filename: str, url: str) -> str:
# Our markdown has no escaping, so we cannot link any
# text containing brackets; strip them from the
# filename we're linking.
filename = re.sub(r"\[|\]", "", filename)
- markdown_link = f"[{filename}]({url})"
- if inline_thumbnail:
- markdown_link = "!" + markdown_link
- return markdown_link
+ return f"[{filename}]({url})"
+
+
+def get_markdown_image_for_url(filename: str, url: str) -> str:
+ return f"!{get_markdown_link_for_url(filename, url)}"