Skip to content

Commit

Permalink
markdown: Use named parameters to add_a helper.
Browse files Browse the repository at this point in the history
This has enough parameters that it benefits from making which is which
explicit.
  • Loading branch information
alexmv authored and timabbott committed Apr 15, 2022
1 parent 452a303 commit 661c333
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions zerver/lib/markdown/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,12 @@ def add_oembed_data(self, root: Element, link: str, extracted_data: Dict[str, An
if oembed_resource_type == "photo":
image = extracted_data.get("image")
if image:
self.add_a(root, image, link, title=title)
self.add_a(
root,
image_url=image,
link=link,
title=title,
)
return True

elif oembed_resource_type == "video":
Expand All @@ -699,12 +704,12 @@ def add_oembed_data(self, root: Element, link: str, extracted_data: Dict[str, An
description = extracted_data.get("description")
self.add_a(
root,
image,
link,
title,
description,
"embed-video message_inline_image",
html,
image_url=image,
link=link,
title=title,
desc=description,
class_attr="embed-video message_inline_image",
data_id=html,
already_thumbnailed=True,
)
return True
Expand Down Expand Up @@ -1150,7 +1155,11 @@ def handle_image_inlining(
(url, text) = found_url.result
actual_url = self.get_actual_image_url(url)
self.add_a(
info["parent"], actual_url, url, title=info["title"], insertion_index=info["index"]
info["parent"],
image_url=actual_url,
link=url,
title=info["title"],
insertion_index=info["index"],
)
if info["remove"] is not None:
info["parent"].remove(info["remove"])
Expand Down Expand Up @@ -1183,12 +1192,10 @@ def handle_youtube_url_inlining(
yt_id = self.youtube_id(url)
self.add_a(
info["parent"],
yt_image,
url,
None,
None,
"youtube-video message_inline_image",
yt_id,
image_url=yt_image,
link=url,
class_attr="youtube-video message_inline_image",
data_id=yt_id,
insertion_index=info["index"],
already_thumbnailed=True,
)
Expand Down Expand Up @@ -1293,8 +1300,8 @@ def run(self, root: Element) -> None:
# Not making use of title and description of images
self.add_a(
root,
dropbox_image["image"],
url,
image_url=dropbox_image["image"],
link=url,
title=dropbox_image.get("title"),
desc=dropbox_image.get("desc", ""),
class_attr=class_attr,
Expand Down

0 comments on commit 661c333

Please sign in to comment.