mirror of
https://github.com/zulip/zulip.git
synced 2025-10-29 19:13:53 +00:00
slack_import: Refactor a convert_slack_formatting.
This prep commit extracts the logic for converting Slack formatted text into Zulip friendly markdown from `convert_to_zulip_markdown` into a new helper function, `convert_slack_formatting`. This is done to make reformating logic be reusable else where such as in the Slack webhook or Slack incoming webhook.
This commit is contained in:
@@ -162,6 +162,13 @@ def convert_slack_workspace_mentions(text: str) -> str:
|
|||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
def convert_slack_formatting(text: str) -> str:
|
||||||
|
text = convert_markdown_syntax(text, SLACK_BOLD_REGEX, "**")
|
||||||
|
text = convert_markdown_syntax(text, SLACK_STRIKETHROUGH_REGEX, "~~")
|
||||||
|
text = convert_markdown_syntax(text, SLACK_ITALIC_REGEX, "*")
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
# Markdown mapping
|
# Markdown mapping
|
||||||
def convert_to_zulip_markdown(
|
def convert_to_zulip_markdown(
|
||||||
text: str,
|
text: str,
|
||||||
@@ -170,10 +177,7 @@ def convert_to_zulip_markdown(
|
|||||||
slack_user_id_to_zulip_user_id: SlackToZulipUserIDT,
|
slack_user_id_to_zulip_user_id: SlackToZulipUserIDT,
|
||||||
) -> tuple[str, list[int], bool]:
|
) -> tuple[str, list[int], bool]:
|
||||||
mentioned_users_id = []
|
mentioned_users_id = []
|
||||||
text = convert_markdown_syntax(text, SLACK_BOLD_REGEX, "**")
|
text = convert_slack_formatting(text)
|
||||||
text = convert_markdown_syntax(text, SLACK_STRIKETHROUGH_REGEX, "~~")
|
|
||||||
text = convert_markdown_syntax(text, SLACK_ITALIC_REGEX, "*")
|
|
||||||
|
|
||||||
text = convert_slack_workspace_mentions(text)
|
text = convert_slack_workspace_mentions(text)
|
||||||
|
|
||||||
# Map Slack channel mention: '<#C5Z73A7RA|general>' to '#**general**'
|
# Map Slack channel mention: '<#C5Z73A7RA|general>' to '#**general**'
|
||||||
|
|||||||
Reference in New Issue
Block a user