Skip to content
Snippets Groups Projects
Commit bc5d6a82 authored by Marcelo Schmidt's avatar Marcelo Schmidt
Browse files

Save parsed html in message object

parent cca26bac
No related branches found
No related tags found
No related merge requests found
......@@ -45,6 +45,7 @@ rocketchat:file
rocketchat:lib
rocketchat:me
rocketchat:mentions
rocketchat:markdown
simple:highlight.js
tap:i18n
tmeasday:crypto-md5
......
......@@ -93,6 +93,7 @@ reload@1.1.3
retry@1.0.3
rocketchat:file@0.0.1
rocketchat:lib@0.0.1
rocketchat:markdown@0.0.1
rocketchat:me@0.0.1
rocketchat:mentions@0.0.1
routepolicy@1.0.5
......
......@@ -9,7 +9,15 @@ Meteor.methods
message.u =
_id: Meteor.userId()
username: Meteor.user().username
message.html = message.msg
if _.trim(message.html) isnt ''
message.html = _.escapeHTML message.html
message = RocketChat.callbacks.run 'beforeSaveMessage', message
message.html = message.html.replace /\n/g, '<br/>'
console.log message
ChatMessage.upsert
rid: message.rid
......
......@@ -42,7 +42,7 @@
</span>
{{/if}}
<div>
{{#emojione}}{{preProcessingMessage}}{{/emojione}}
{{{html}}}
</div>
{{/if}}
{{/if}}
......
###
# Process selected markdown in text messages
# @param {Object} message - The message object
###
class Markdown
constructor: (message) ->
msg = message.html
# Process MD text for code ```
msgParts = msg.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>"
msg = msgParts.join('')
# Process MD text 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 'beforeSaveMessage', Markdown
Package.describe({
name: 'rocketchat:markdown',
version: '0.0.1',
summary: 'Message pre-processor that will process selected markdown notations',
git: ''
});
Package.onUse(function(api) {
api.versionsFrom('1.0');
api.use([
'coffeescript',
'simple:highlight.js',
'rocketchat:lib@0.0.1'
]);
api.addFiles('markdown.coffee', ['server','client']);
});
Package.onTest(function(api) {
});
......@@ -12,8 +12,36 @@ Meteor.methods
message.u = Meteor.users.findOne Meteor.userId(), fields: username: 1
message.ts = new Date()
message = RocketChat.callbacks.run 'beforeSaveMessage', message
message.html = message.msg
# if _.trim(message.html) isnt ''
# message.html = _.escapeHTML message.html
# message.html = message.html.replace /\n/g, '<br/>'
# Process links in message
# msg = Autolinker.link(msg, { stripPrefix: false, twitter: false })
# 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>')
# Highlight mentions
# if not message.mentions? or message.mentions.length is 0
# mentions = _.map message.mentions, (mention) ->
# return mention.username or mention
# 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 = RocketChat.callbacks.run 'beforeSaveMessage', message
if _.trim(message.html) isnt ''
message.html = _.escapeHTML message.html
message = RocketChat.callbacks.run 'beforeSaveMessage', message
message.html = message.html.replace /\n/g, '<br/>'
# console.log "message", message
###
......
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