slack_regex: Update Slack regex handle multiline strings.

This prep commit modifies the Slack text regex in
`slack_message_conversion.py` to use the `re.MULTILINE` flag capture
formatted strings that are adjacent to newline or end of line.

These kinds of strings are likely not uncommon to be generated by Slack
exporter itself and our Slack message block and attachment formatters
(`render_blocks` and `render_attachments`) also produces them.

This also fixes Slack webhook integration's
`test_message_with_complex_formatted_texts` which was previously
expecting false output.

Fixes part of #30827.
This commit is contained in:
PieterCK
2024-11-19 16:05:06 +07:00
committed by Tim Abbott
parent 6c1818fa46
commit 8992435caf
3 changed files with 12 additions and 2 deletions

View File

@@ -183,7 +183,7 @@ def convert_markdown_syntax(text: str, pattern: str, zulip_keyword: str) -> str:
+ match.group(6)
)
return regex.sub(pattern, replace_slack_format, text, flags=re.VERBOSE)
return regex.sub(pattern, replace_slack_format, text, flags=re.VERBOSE | re.MULTILINE)
def convert_slack_workspace_mentions(text: str) -> str:

View File

@@ -89,6 +89,16 @@
"name": "unicode_quotes",
"input": "«~strike~» 「*bold*」 ❰_italic_❱",
"conversion_output": "«~~strike~~» 「**bold**」 ❰*italic*❱"
},
{
"name": "new_line_test",
"input": "\n*abc*\n_helo_\n~stike~\n",
"conversion_output": "\n**abc**\n*helo*\n~~stike~~\n"
},
{
"name": "zero_width_identical_bold_matches_test",
"input": "*foo*\n*foo*\n*foo*",
"conversion_output": "**foo**\n**foo**\n**foo**"
}
]
}

View File

@@ -271,7 +271,7 @@ class SlackWebhookTests(WebhookTestCase):
)
def test_message_with_complex_formatted_texts(self) -> None:
message_body = "this is text messages with overlapping formatting\n_**bold with italic**_\n~**bold with strike through**~\n~*italic with strike through*~\n~***all three***~"
message_body = "this is text messages with overlapping formatting\n***bold with italic***\n~~**bold with strike through**~~\n~~*italic with strike through*~~\n~~***all three***~~"
expected_message = EXPECTED_MESSAGE.format(user=USER, message=message_body)
self.check_webhook(
"message_with_complex_formatted_texts",