Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
markdown: Update max inline preview from 10 to 24.
Trident Pancakec6ea673cc940
diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.pyindex 38bfe0503ed..86fda7101ec 100644--- a/zerver/lib/markdown/__init__.py+++ b/zerver/lib/markdown/__init__.py@@ -628,7 +628,7 @@ IMAGE_EXTENSIONS = [".bmp", ".gif", ".jpe", ".jpeg", ".jpg", ".png", ".webp"]class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor):TWITTER_MAX_IMAGE_HEIGHT = 400TWITTER_MAX_TO_PREVIEW = 3- INLINE_PREVIEW_LIMIT_PER_MESSAGE = 10+ INLINE_PREVIEW_LIMIT_PER_MESSAGE = 24def __init__(self, zmd: "ZulipMarkdown") -> None:super().__init__(zmd)diff --git a/zerver/tests/test_markdown.py b/zerver/tests/test_markdown.pyindex 5903ea5e1cb..912aa5dde01 100644--- a/zerver/tests/test_markdown.py+++ b/zerver/tests/test_markdown.py@@ -7,6 +7,7 @@ from typing import Any, Dict, List, Optional, Set, Tuple, castfrom unittest import mockimport orjson+from bs4 import BeautifulSoupfrom django.conf import settingsfrom django.test import override_settingsfrom markdown import Markdown@@ -23,6 +24,7 @@ from zerver.lib.create_user import create_userfrom zerver.lib.emoji import get_emoji_urlfrom zerver.lib.exceptions import JsonableError, MarkdownRenderingErrorfrom zerver.lib.markdown import (+ InlineInterestingLinkProcessor,MarkdownListPreprocessor,MessageRenderingResult,clear_state_for_testing,@@ -661,6 +663,38 @@ class MarkdownTest(ZulipTestCase):converted = markdown_convert_wrapper(content)self.assertIn(converted, thumbnail_img)+ @override_settings(INLINE_IMAGE_PREVIEW=True)+ def test_max_inline_preview(self) -> None:+ image_links = []+ # Add a youtube link within a spoiler to ensure other link types are counted+ image_links.append(+ """```spoiler Check out this PyCon video\nhttps://www.youtube.com/watch?v=0c46YHS3RY8\n```"""+ )+ # Add a link within blockquote to test that it does NOT get counted+ image_links.append("> http://cdn.wallpapersafari.com/spoiler/dont_count.jpeg\n")+ # Using INLINE_PREVIEW_LIMIT_PER_MESSAGE - 1 because of the one link in a spoiler added already+ for x in range(InlineInterestingLinkProcessor.INLINE_PREVIEW_LIMIT_PER_MESSAGE - 1):+ image_links.append("http://cdn.wallpapersafari.com/{}/6/16eVjx.jpeg".format(x))+ within_limit_content = "\n".join(image_links)+ above_limit_content = (+ within_limit_content + "\nhttp://cdn.wallpapersafari.com/above/0/6/16eVjx.jpeg"+ )++ # When the number of image links is within the preview limit, the+ # output should contain the same number of inline images.+ converted = markdown_convert_wrapper(within_limit_content)+ soup = BeautifulSoup(converted, "html.parser")+ self.assert_length(+ soup(class_="message_inline_image"),+ InlineInterestingLinkProcessor.INLINE_PREVIEW_LIMIT_PER_MESSAGE,+ )++ # When the number of image links is over the limit, then there should+ # be zero inline images.+ converted = markdown_convert_wrapper(above_limit_content)+ soup = BeautifulSoup(converted, "html.parser")+ self.assert_length(soup(class_="message_inline_image"), 0)+@override_settings(INLINE_IMAGE_PREVIEW=True)def test_inline_image_quoted_blocks(self) -> None:content = "http://cdn.wallpapersafari.com/13/6/16eVjx.jpeg"