disable rendering media links/syntaxes when there are inside simple backtick

pull/932/head
kakawait 10 years ago
parent 3838bac984
commit 07073fe21b
  1. 23
      packages/rocketchat-autolinker/autolinker.coffee
  2. 12
      packages/rocketchat-spotify/spotify.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('')

@ -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 = []
@ -46,8 +47,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

Loading…
Cancel
Save