parent
cca26bac54
commit
96702b920a
@ -0,0 +1,13 @@ |
||||
### |
||||
# AutoLinker is a named function that will replace links on messages |
||||
# @param {Object} message - The message object |
||||
### |
||||
|
||||
class AutoLinker |
||||
constructor: (message) -> |
||||
if _.trim message.html |
||||
message.html = Autolinker.link(message.html, { stripPrefix: false, twitter: false }) |
||||
|
||||
return message |
||||
|
||||
RocketChat.callbacks.add 'renderMessage', AutoLinker |
@ -0,0 +1,22 @@ |
||||
Package.describe({ |
||||
name: 'rocketchat:autolinker', |
||||
version: '0.0.1', |
||||
summary: 'Message pre-processor that will translate links on messages', |
||||
git: '' |
||||
}); |
||||
|
||||
Package.onUse(function(api) { |
||||
api.versionsFrom('1.0'); |
||||
|
||||
api.use([ |
||||
'coffeescript', |
||||
'konecty:autolinker', |
||||
'rocketchat:lib@0.0.1' |
||||
]); |
||||
|
||||
api.addFiles('autolinker.coffee', ['server','client']); |
||||
}); |
||||
|
||||
Package.onTest(function(api) { |
||||
|
||||
}); |
@ -0,0 +1,13 @@ |
||||
### |
||||
# Emojione is a named function that will replace emojis |
||||
# @param {Object} message - The message object |
||||
### |
||||
|
||||
class Emojione |
||||
constructor: (message) -> |
||||
if _.trim message.html |
||||
message.html = emojione.toImage(message.html) |
||||
|
||||
return message |
||||
|
||||
RocketChat.callbacks.add 'renderMessage', Emojione |
@ -0,0 +1,22 @@ |
||||
Package.describe({ |
||||
name: 'rocketchat:emojione', |
||||
version: '0.0.1', |
||||
summary: 'Message pre-processor that will translate emojis', |
||||
git: '' |
||||
}); |
||||
|
||||
Package.onUse(function(api) { |
||||
api.versionsFrom('1.0'); |
||||
|
||||
api.use([ |
||||
'coffeescript', |
||||
'qnub:emojione', |
||||
'rocketchat:lib@0.0.1' |
||||
]); |
||||
|
||||
api.addFiles('emojione.coffee', ['server','client']); |
||||
}); |
||||
|
||||
Package.onTest(function(api) { |
||||
|
||||
}); |
@ -0,0 +1,38 @@ |
||||
### |
||||
# Highlight is a named function that will highlight ``` messages |
||||
# @param {Object} message - The message object |
||||
### |
||||
|
||||
class Highlight |
||||
|
||||
# If message starts with ```, replace it for text formatting |
||||
constructor: (message) -> |
||||
|
||||
if _.trim message.html |
||||
# Separate text in code blocks and non code blocks |
||||
msgParts = message.html.split(/(```.*\n[\s\S]*?\n```)/) |
||||
|
||||
for part, index in msgParts |
||||
# Verify if this part is code |
||||
codeMatch = part.match(/```(.*)\n([\s\S]*?)\n```/) |
||||
if codeMatch? |
||||
# Process highlight if this part is code |
||||
lang = codeMatch[1] |
||||
code = codeMatch[2] |
||||
if lang not in hljs.listLanguages() |
||||
result = hljs.highlightAuto code |
||||
else |
||||
result = hljs.highlight lang, code |
||||
msgParts[index] = "<pre><code class='hljs " + result.language + "'>" + result.value + "</code></pre>" |
||||
else |
||||
# Escape html and fix line breaks for non code blocks |
||||
part = _.escapeHTML part |
||||
part = part.replace /\n/g, '<br/>' |
||||
msgParts[index] = part |
||||
|
||||
# Re-mount message |
||||
message.html = msgParts.join('') |
||||
|
||||
return message |
||||
|
||||
RocketChat.callbacks.add 'renderMessage', Highlight, RocketChat.callbacks.priority.HIGH |
@ -0,0 +1,22 @@ |
||||
Package.describe({ |
||||
name: 'rocketchat:highlight', |
||||
version: '0.0.1', |
||||
summary: 'Message pre-processor that will highlight code syntax', |
||||
git: '' |
||||
}); |
||||
|
||||
Package.onUse(function(api) { |
||||
api.versionsFrom('1.0'); |
||||
|
||||
api.use([ |
||||
'coffeescript', |
||||
'simple:highlight.js', |
||||
'rocketchat:lib@0.0.1' |
||||
]); |
||||
|
||||
api.addFiles('highlight.coffee', ['server','client']); |
||||
}); |
||||
|
||||
Package.onTest(function(api) { |
||||
|
||||
}); |
@ -0,0 +1,19 @@ |
||||
### |
||||
# Markdown is a named function that will parse markdown syntax |
||||
# @param {Object} message - The message object |
||||
### |
||||
|
||||
class Markdown |
||||
constructor: (message) -> |
||||
|
||||
msg = message.html or '' |
||||
|
||||
# Process MD like for strong, italic and strike |
||||
msg = msg.replace(/\*([^*]+)\*/g, '<strong>$1</strong>') |
||||
msg = msg.replace(/\_([^_]+)\_/g, '<i>$1</i>') |
||||
msg = msg.replace(/\~([^_]+)\~/g, '<strike>$1</strike>') |
||||
|
||||
message.html = msg |
||||
return message |
||||
|
||||
RocketChat.callbacks.add 'renderMessage', Markdown |
@ -0,0 +1,21 @@ |
||||
Package.describe({ |
||||
name: 'rocketchat:markdown', |
||||
version: '0.0.1', |
||||
summary: 'Message pre-processor that will parse markdown syntax', |
||||
git: '' |
||||
}); |
||||
|
||||
Package.onUse(function(api) { |
||||
api.versionsFrom('1.0'); |
||||
|
||||
api.use([ |
||||
'coffeescript', |
||||
'rocketchat:lib@0.0.1' |
||||
]); |
||||
|
||||
api.addFiles('markdown.coffee', ['server','client']); |
||||
}); |
||||
|
||||
Package.onTest(function(api) { |
||||
|
||||
}); |
@ -0,0 +1,23 @@ |
||||
### |
||||
# Mentions is a named function that will process Mentions |
||||
# @param {Object} message - The message object |
||||
### |
||||
|
||||
class MentionsClient |
||||
constructor: (message) -> |
||||
if _.trim message.html |
||||
msg = message.html |
||||
|
||||
mentions = [] |
||||
message.msg.replace /(?:^|\s|\n)(?:@)([A-Za-z0-9-_.]+)/g, (match, mention) -> |
||||
mentions.push mention |
||||
if mentions.length isnt 0 |
||||
mentions = _.unique mentions |
||||
mentions = mentions.join('|') |
||||
msg = msg.replace new RegExp("(?:^|\\s)(@(#{mentions}))(?:\\s|$)", 'g'), (match, mention, username) -> |
||||
return match.replace mention, "<a href=\"\" class=\"mention-link\" data-username=\"#{username}\">#{mention}</a>" |
||||
|
||||
message.html = msg |
||||
return message |
||||
|
||||
RocketChat.callbacks.add 'renderMessage', MentionsClient |
Loading…
Reference in new issue