Skip to content

Commit

Permalink
Merge branch 'master' of github.com:RocketChat/Rocket.Chat
Browse files Browse the repository at this point in the history
  • Loading branch information
marceloschmidt committed Sep 30, 2015
2 parents 7f37669 + 6bca1ca commit 08eee0f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
23 changes: 12 additions & 11 deletions packages/rocketchat-autolinker/autolinker.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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('')
Expand Down
12 changes: 6 additions & 6 deletions packages/rocketchat-spotify/spotify.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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<a href="' + item.url + '" target="_blank">' + item.source + '</a>$2'
msgParts[index] = part
msgParts[index] = part.replace re, '$1<a href="' + item.url + '" target="_blank">' + item.source + '</a>$2'
message.html = msgParts.join ''

return message
Expand Down

0 comments on commit 08eee0f

Please sign in to comment.