diff options
author | Elias Nahum <nahumhbl@gmail.com> | 2016-04-01 12:40:07 -0300 |
---|---|---|
committer | Elias Nahum <nahumhbl@gmail.com> | 2016-04-01 14:08:02 -0300 |
commit | 9ec459526a2bf4d119ab779473c9606c524b6131 (patch) | |
tree | 06cc009b3d0fae371694bad301d60ba4182c0f0c /webapp/utils/utils.jsx | |
parent | ff01fc7337eedc51c84610a8c6bf578e4f42b9df (diff) | |
download | chat-9ec459526a2bf4d119ab779473c9606c524b6131.tar.gz chat-9ec459526a2bf4d119ab779473c9606c524b6131.tar.bz2 chat-9ec459526a2bf4d119ab779473c9606c524b6131.zip |
Rename extractLinks to extractFirstLink
Diffstat (limited to 'webapp/utils/utils.jsx')
-rw-r--r-- | webapp/utils/utils.jsx | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/webapp/utils/utils.jsx b/webapp/utils/utils.jsx index 9af36f9dd..dc9291ab7 100644 --- a/webapp/utils/utils.jsx +++ b/webapp/utils/utils.jsx @@ -313,9 +313,8 @@ export function getTimestamp() { } // extracts links not styled by Markdown -export function extractLinks(text) { - const pattern = /(^|[\s\n]|<br\/?>)((?:https?|ftp):\/\/[\-A-Z0-9+\u0026\u2019@#\/%?=()~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~()_|])/gi; - let links; +export function extractFirstLink(text) { + const pattern = /(^|[\s\n]|<br\/?>)((?:https?|ftp):\/\/[\-A-Z0-9+\u0026\u2019@#\/%?=()~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~()_|])/i; let inText = text; // strip out code blocks @@ -324,13 +323,12 @@ export function extractLinks(text) { // strip out inline markdown images inText = inText.replace(/!\[[^\]]*\]\([^\)]*\)/g, ''); - links = inText.match(pattern) || []; + const match = pattern.exec(inText); + if (match) { + return match[0].trim(); + } - return links.map( - (url) => { - return url.trim(); - } - ); + return ''; } export function escapeRegExp(string) { |