zulip_updates: Fix line removal logic for bulleted lists.

This commit is contained in:
Tim Abbott
2024-04-02 15:05:25 -07:00
parent c7a08f3b77
commit 563485a37e
2 changed files with 6 additions and 1 deletions

View File

@@ -1444,4 +1444,4 @@ def set_visibility_policy_possible(user_profile: UserProfile, message: Message)
def remove_single_newlines(content: str) -> str:
content = content.strip("\n")
return re.sub(r"(?<!\n)\n(?!\n)", " ", content)
return re.sub(r"(?<!\n)\n(?![\n0-9*-])", " ", content)

View File

@@ -180,3 +180,8 @@ class ZulipUpdateAnnouncementsTest(ZulipTestCase):
input_text = "This is a sentence.\nThis is another sentence.\nThis is a third sentence.\nThis is a fourth sentence."
expected_output = "This is a sentence. This is another sentence. This is a third sentence. This is a fourth sentence."
self.assertEqual(remove_single_newlines(input_text), expected_output)
# Bulleted lists on lines.
input_text = "- This is a bullet.\n- This is another bullet.\n\n1. This is a list\n1. This is more list."
expected_output = "- This is a bullet.\n- This is another bullet.\n\n1. This is a list\n1. This is more list."
self.assertEqual(remove_single_newlines(input_text), expected_output)