mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
slack_regex: Remove unnecessary inner capture group.
The inner capture groups of the Slack text regex tries to captures the formatted string. For an unclear reason, we're currently using two similar capture groups despite the fact that only using the second capture groups would suffice. This removes the first capture groups.
This commit is contained in:
@@ -60,7 +60,7 @@ SLACK_STRIKETHROUGH_REGEX = r"""
|
||||
[\p{P}\p{Zs}\p{S}]|^
|
||||
)
|
||||
(\~) # followed by a ~
|
||||
([ -)+-}—]*)([ -}]+) # any character except ~
|
||||
([ -}]+) # any character except ~
|
||||
(\~) # followed by a ~
|
||||
(
|
||||
# Capture punctuation, white space, symbols or end of
|
||||
@@ -80,7 +80,7 @@ SLACK_ITALIC_REGEX = r"""
|
||||
[\p{P}\p{Zs}\p{S}]|^
|
||||
)
|
||||
(\_)
|
||||
([ -^`~—]*)([ -^`-~]+) # any character except _
|
||||
([ -^`-~]+) # any character except _
|
||||
(\_)
|
||||
(
|
||||
(?![_`@\\\p{Pi}\p{Ps}])
|
||||
@@ -95,7 +95,7 @@ SLACK_BOLD_REGEX = r"""
|
||||
[\p{P}\p{Zs}\p{S}]|^
|
||||
)
|
||||
(\*)
|
||||
([ -)+-~—]*)([ -)+-~]+) # any character except *
|
||||
([ -)+-~]+) # any character except *
|
||||
(\*)
|
||||
(
|
||||
(?![*`@\\\p{Pi}\p{Ps}])
|
||||
@@ -174,14 +174,7 @@ def convert_markdown_syntax(text: str, pattern: str, zulip_keyword: str) -> str:
|
||||
"""
|
||||
|
||||
def replace_slack_format(match: regex.Match[str]) -> str:
|
||||
return (
|
||||
match.group(1)
|
||||
+ zulip_keyword
|
||||
+ match.group(3)
|
||||
+ match.group(4)
|
||||
+ zulip_keyword
|
||||
+ match.group(6)
|
||||
)
|
||||
return match.group(1) + zulip_keyword + match.group(3) + zulip_keyword + match.group(5)
|
||||
|
||||
return regex.sub(pattern, replace_slack_format, text, flags=re.VERBOSE | re.MULTILINE)
|
||||
|
||||
|
Reference in New Issue
Block a user