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:
PieterCK
2024-11-21 15:22:04 +07:00
committed by Tim Abbott
parent 4b472611d0
commit 6543dadd0f

View File

@@ -162,6 +162,13 @@ def convert_slack_workspace_mentions(text: str) -> str:
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
def convert_to_zulip_markdown(
text: str,
@@ -170,10 +177,7 @@ def convert_to_zulip_markdown(
slack_user_id_to_zulip_user_id: SlackToZulipUserIDT,
) -> tuple[str, list[int], bool]:
mentioned_users_id = []
text = convert_markdown_syntax(text, SLACK_BOLD_REGEX, "**")
text = convert_markdown_syntax(text, SLACK_STRIKETHROUGH_REGEX, "~~")
text = convert_markdown_syntax(text, SLACK_ITALIC_REGEX, "*")
text = convert_slack_formatting(text)
text = convert_slack_workspace_mentions(text)
# Map Slack channel mention: '<#C5Z73A7RA|general>' to '#**general**'