mirror of https://github.com/zulip/zulip.git
slack_regex: Update Slack text regex capture newlines.
This prep commit modifies the Slack text regex in `slack_message_conversion.py` to include the newline character (`\n`) as part of the first and last capture groups. Previously, the regex in `slack_message_conversion.py` couldn't capture and reformat strings surrounded by newlines, such as "\n*ABC*\n". This kind of string is likely not uncommon to be generated by both the Slack exporter itself or by our Slack message block and attachment formatters (`render_blocks` and `render_attachments`).
This commit is contained in:
parent
49eca01cfc
commit
414c72172a
|
@ -48,25 +48,25 @@ SLACK_USERMENTION_REGEX = r"""
|
|||
# Hence, ~stri~ke doesn't format the word in Slack, but ~~stri~~ke
|
||||
# formats the word in Zulip
|
||||
SLACK_STRIKETHROUGH_REGEX = r"""
|
||||
(^|[ -(]|[+-/]|\*|\_|[:-?]|\{|\[|\||\^) # Start after specified characters
|
||||
(\n|^|[ -(]|[+-/]|\*|\_|[:-?]|\{|\[|\||\^) # Start after specified characters
|
||||
(\~) # followed by an asterisk
|
||||
([ -)+-}—]*)([ -}]+) # any character except asterisk
|
||||
(\~) # followed by an asterisk
|
||||
($|[ -']|[+-/]|[:-?]|\*|\_|\}|\)|\]|\||\^) # ends with specified characters
|
||||
(\n|$|[ -']|[+-/]|[:-?]|\*|\_|\}|\)|\]|\||\^) # ends with specified characters
|
||||
"""
|
||||
SLACK_ITALIC_REGEX = r"""
|
||||
(^|[ -*]|[+-/]|[:-?]|\{|\[|\||\^|~)
|
||||
(\n|^|[ -*]|[+-/]|[:-?]|\{|\[|\||\^|~)
|
||||
(\_)
|
||||
([ -^`~—]*)([ -^`-~]+) # any character
|
||||
(\_)
|
||||
($|[ -']|[+-/]|[:-?]|\}|\)|\]|\*|\||\^|~)
|
||||
(\n|$|[ -']|[+-/]|[:-?]|\}|\)|\]|\*|\||\^|~)
|
||||
"""
|
||||
SLACK_BOLD_REGEX = r"""
|
||||
(^|[ -(]|[+-/]|[:-?]|\{|\[|\_|\||\^|~)
|
||||
(\n|^|[ -(]|[+-/]|[:-?]|\{|\[|\_|\||\^|~)
|
||||
(\*)
|
||||
([ -)+-~—]*)([ -)+-~]+) # any character
|
||||
(\*)
|
||||
($|[ -']|[+-/]|[:-?]|\}|\)|\]|\_|\||\^|~)
|
||||
(\n|$|[ -']|[+-/]|[:-?]|\}|\)|\]|\_|\||\^|~)
|
||||
"""
|
||||
|
||||
|
||||
|
|
|
@ -84,6 +84,11 @@
|
|||
"name": "italic_and_strike_conversion",
|
||||
"input": "_~italic~_ and ~_strike_~",
|
||||
"conversion_output": "*~~italic~~* and ~~*strike*~~"
|
||||
},
|
||||
{
|
||||
"name": "new_line_test",
|
||||
"input": "\n*abc*\n",
|
||||
"conversion_output": "\n**abc**\n"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue