aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2019-03-26 17:30:15 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2019-03-26 18:28:47 +0100
commit0f4b2c4c2b7305fd41d405a8f7ce755d27867eef (patch)
tree71635a92ece11b9678f29e689bee417f25abd850 /wee_slack.py
parentea27ddfedcb4f68ff2e478557e680096b8701b12 (diff)
downloadwee-slack-0f4b2c4c2b7305fd41d405a8f7ce755d27867eef.tar.gz
Improve detection of incoming formatting characters
This replaces the trailing whitespace match with a non-consuming lookahead so that strings like '*one* *two*' match correctly, and uses \w instead of hard coded ascii characters. This is taken from #359 and updated. Closes #359
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 1c15b04..331972a 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -2898,14 +2898,16 @@ def process_emoji_changed(message_json, eventrouter, **kwargs):
###### New module/global methods
def render_formatting(text):
- text = re.sub(r'(^| )\*([^*\n`]+)\*([^a-zA-Z0-9_]|$)',
- r'\1{}*\2*{}\3'.format(w.color(config.render_bold_as),
+ text = re.sub(r'(^| )\*([^*\n`]+)\*(?=[^\w]|$)',
+ r'\1{}*\2*{}'.format(w.color(config.render_bold_as),
w.color('-' + config.render_bold_as)),
- text)
- text = re.sub(r'(^| )_([^_\n`]+)_([^a-zA-Z0-9_]|$)',
- r'\1{}_\2_{}\3'.format(w.color(config.render_italic_as),
+ text,
+ flags=re.UNICODE)
+ text = re.sub(r'(^| )_([^_\n`]+)_(?=[^\w]|$)',
+ r'\1{}_\2_{}'.format(w.color(config.render_italic_as),
w.color('-' + config.render_italic_as)),
- text)
+ text,
+ flags=re.UNICODE)
return text