diff options
author | Ben Kelly <bk@ancilla.ca> | 2017-04-28 14:10:48 -0400 |
---|---|---|
committer | Ben Kelly <btk@google.com> | 2017-07-12 12:35:07 -0400 |
commit | ce116df2c369ae7b24255ba6e2754040adacfb30 (patch) | |
tree | 629a0be88cda5a3b8bce48e654228822a05f1210 /wee_slack.py | |
parent | 0c96ed1ccc93833c1bc31c8af822f37bb5fd0ba8 (diff) | |
download | wee-slack-ce116df2c369ae7b24255ba6e2754040adacfb30.tar.gz |
Disable formatting for messages with `mrkdwn` unset
Signed-off-by: Ben Kelly <btk@google.com>
Signed-off-by: Ben Kelly <bk@ancilla.ca>
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/wee_slack.py b/wee_slack.py index a0600c0..c15d365 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -2438,6 +2438,17 @@ def process_reaction_removed(message_json, eventrouter, **kwargs): ###### New module/global methods +def render_formatting(text): + text = re.sub(r'(^| )\*([^*]+)\*([^a-zA-Z0-9_]|$)', + r'\1{}\2{}\3'.format(w.color(config.render_bold_as), + w.color('-' + config.render_bold_as)), + text) + text = re.sub(r'(^| )_([^_]+)_([^a-zA-Z0-9_]|$)', + r'\1{}\2{}\3'.format(w.color(config.render_italic_as), + w.color('-' + config.render_italic_as)), + text) + return text + def render(message_json, team, channel, force=False): # If we already have a rendered version in the object, just return that. @@ -2466,14 +2477,8 @@ def render(message_json, team, channel, force=False): text = text.replace("<", "<") text = text.replace(">", ">") text = text.replace("&", "&") - text = re.sub(r'(^| )\*([^*]+)\*([^a-zA-Z0-9_]|$)', - r'\1{}\2{}\3'.format(w.color(config.render_bold_as), - w.color('-' + config.render_bold_as)), - text) - text = re.sub(r'(^| )_([^_]+)_([^a-zA-Z0-9_]|$)', - r'\1{}\2{}\3'.format(w.color(config.render_italic_as), - w.color('-' + config.render_italic_as)), - text) + if message_json.get('mrkdwn', True): + text = render_formatting(text) # if self.threads: # text += " [Replies: {} Thread ID: {} ] ".format(len(self.threads), self.thread_id) |