Skip to content
Snippets Groups Projects
Commit a912a2b2 authored by Gabriel Engel's avatar Gabriel Engel
Browse files

Merge pull request #499 from RocketChat/improve-autolinker

Prevent autolinker to process insice multiline block codes and only l…
parents 8063ba1a c6d3ddbd
No related branches found
No related tags found
No related merge requests found
...@@ -6,8 +6,24 @@ ...@@ -6,8 +6,24 @@
class AutoLinker class AutoLinker
constructor: (message) -> constructor: (message) ->
if _.trim message.html if _.trim message.html
message.html = Autolinker.link(message.html, { stripPrefix: false, twitter: false }) # Separate text in code blocks and non code blocks
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
# Re-mount message
message.html = msgParts.join('')
return message return message
RocketChat.callbacks.add 'renderMessage', AutoLinker RocketChat.callbacks.add 'renderMessage', AutoLinker
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment