diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2017-09-05 12:39:07 -0400 |
---|---|---|
committer | Saturnino Abril <saturnino.abril@gmail.com> | 2017-09-06 00:39:07 +0800 |
commit | 575864c917dbbe6b58d3e4534c3015327f2cb088 (patch) | |
tree | 547ecd46393b82961e4e5518d47273d8bb4ed2f6 /webapp/utils/post_utils.jsx | |
parent | daed8ffbf6151f01866b9299574fdf6764c8b7bd (diff) | |
download | chat-575864c917dbbe6b58d3e4534c3015327f2cb088.tar.gz chat-575864c917dbbe6b58d3e4534c3015327f2cb088.tar.bz2 chat-575864c917dbbe6b58d3e4534c3015327f2cb088.zip |
PLT-7474 Stopped requiring confirmation for mentions in code blocks (#7375)
* PLT-7474 Stopped requiring confirmation for mentions in code blocks
* Stopped mentioning people from code blocks using ~~~
Diffstat (limited to 'webapp/utils/post_utils.jsx')
-rw-r--r-- | webapp/utils/post_utils.jsx | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/webapp/utils/post_utils.jsx b/webapp/utils/post_utils.jsx index 1ff16a5ab..d37e6c26d 100644 --- a/webapp/utils/post_utils.jsx +++ b/webapp/utils/post_utils.jsx @@ -113,5 +113,15 @@ export function containsAtMention(text, key) { } // This doesn't work for at mentions containing periods or hyphens - return new RegExp(`\\B${key}\\b`, 'i').test(text); + return new RegExp(`\\B${key}\\b`, 'i').test(removeCode(text)); +} + +// Returns a given text string with all Markdown code replaced with whitespace. +export function removeCode(text) { + // These patterns should match the ones in app/notification.go, except JavaScript doesn't + // support \z for the end of the text in multiline mode, so we use $(?![\r\n]) + const codeBlockPattern = /^[^\S\n]*[`~]{3}.*$[\s\S]+?(^[^\S\n]*[`~]{3}$|$(?![\r\n]))/m; + const inlineCodePattern = /`+(?:.+?|.*?\n(.*?\S.*?\n)*.*?)`+/m; + + return text.replace(codeBlockPattern, '').replace(inlineCodePattern, ' '); } |