diff --git a/packages/rocketchat-autolinker/autolinker.coffee b/packages/rocketchat-autolinker/autolinker.coffee index 06ccd95416a3..5fbd91097171 100644 --- a/packages/rocketchat-autolinker/autolinker.coffee +++ b/packages/rocketchat-autolinker/autolinker.coffee @@ -7,19 +7,20 @@ class AutoLinker constructor: (message) -> if _.trim message.html # Separate text in code blocks and non code blocks - msgParts = message.html.split(/(```\w*[\n\ ]?[\s\S]*?```+?)/) + msgParts = message.html.split /(```\w*[\n ]?[\s\S]*?```+?)|(`(?:[^`]+)`)/ for part, index in msgParts - # Verify if this part is code - codeMatch = part.match(/```(\w*)[\n\ ]?([\s\S]*?)```+?/) - if not codeMatch? - msgParts[index] = Autolinker.link part, - stripPrefix: false - twitter: false - replaceFn: (autolinker, match) -> - if match.getType() is 'url' - return /(:\/\/|www\.).+/.test match.matchedText - return true + if part?.length? > 0 + # Verify if this part is code + codeMatch = part.match /(?:```(\w*)[\n ]?([\s\S]*?)```+?)|(?:`(?:[^`]+)`)/ + if not codeMatch? + msgParts[index] = Autolinker.link part, + stripPrefix: false + twitter: false + replaceFn: (autolinker, match) -> + if match.getType() is 'url' + return /(:\/\/|www\.).+/.test match.matchedText + return true # Re-mount message message.html = msgParts.join('') diff --git a/packages/rocketchat-spotify/spotify.coffee b/packages/rocketchat-spotify/spotify.coffee index d776a83eb71b..e5997acf7223 100644 --- a/packages/rocketchat-spotify/spotify.coffee +++ b/packages/rocketchat-spotify/spotify.coffee @@ -7,13 +7,14 @@ class Spotify process = (message, source, callback) -> if _.trim source # Separate text in code blocks and non code blocks - msgParts = source.split(/(```\w*[\n\ ]?[\s\S]*?```+?)/) + msgParts = source.split /(```\w*[\n ]?[\s\S]*?```+?)|(`(?:[^`]+)`)/ for part, index in msgParts # Verify if this part is code - codeMatch = part.match(/```(\w*)[\n\ ]?([\s\S]*?)```+?/) - if not codeMatch? - callback message, msgParts, index, part + if part?.length? > 0 + codeMatch = part.match /(?:```(\w*)[\n ]?([\s\S]*?)```+?)|(?:`(?:[^`]+)`)/ + if not codeMatch? + callback message, msgParts, index, part @transform: (message) -> urls = [] @@ -47,8 +48,7 @@ class Spotify if item.source quotedSource = item.source.replace /[\\^$.*+?()[\]{}|]/g, '\\$&' re = new RegExp '(^|\\s)' + quotedSource + '(\\s|$)', 'g' - part = part.replace re, '$1' + item.source + '$2' - msgParts[index] = part + msgParts[index] = part.replace re, '$1' + item.source + '$2' message.html = msgParts.join '' return message