Skip to content
Snippets Groups Projects
Commit c6d3ddbd authored by Rodrigo Nascimento's avatar Rodrigo Nascimento
Browse files

Prevent autolinker to process insice multiline block codes and only link urls...

Prevent autolinker to process insice multiline block codes and only link urls containing :// or www.
parent 8063ba1a
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