aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Kelly <bk@ancilla.ca>2017-07-13 09:37:22 -0400
committerGitHub <noreply@github.com>2017-07-13 09:37:22 -0400
commitac47c2e1ac4a80b4d6a01d1f7ab0659d3d538518 (patch)
tree7b435aec34457ab947d16086971cb5d75d9e4613
parent627f017b5b1579f7afa5702c5edc43ff7e6a7b87 (diff)
parentce116df2c369ae7b24255ba6e2754040adacfb30 (diff)
downloadwee-slack-ac47c2e1ac4a80b4d6a01d1f7ab0659d3d538518.tar.gz
Merge pull request #371 from ToxicFrog/toxicfrog/mrkdwn
Disable formatting for messages with `mrkdwn` unset
-rw-r--r--wee_slack.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 269904f..bf45ffc 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("&lt;", "<")
text = text.replace("&gt;", ">")
text = text.replace("&amp;", "&")
- 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)