Last active
April 7, 2016 16:02
-
-
Save mathieuancelin/57e275f1d6d0a100069699c5f246ec5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var AutoImage = function AutoImage(message) { | |
| if (_.trim(message.html)) { | |
| message.html = message.html.split(/ /).map(function (part, index) { | |
| if (part && part.length && part.length > 0) { | |
| var codeMatch = part.match(/(?:```(\w*)[\n ]?([\s\S]*?)```+?)|(?:`(?:[^`]+)`)/); | |
| var imgHrefMatch = part.match(/href=/i); | |
| if (!codeMatch && !imgHrefMatch) { | |
| return part.replace(/(https?:\/\/.*\.(?:png|jpeg|jpg|gif))/i, '<img src="$1" />'); | |
| } else { | |
| return part; | |
| } | |
| } | |
| }).join(' '); | |
| return message; | |
| } | |
| }; | |
| RocketChat.callbacks.add('renderMessage', AutoImage); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Package.describe({ | |
| name: 'rocketchat:autoimage', | |
| version: '0.0.1', | |
| summary: 'Message pre-processor that will transform image links on messages', | |
| git: '' | |
| }); | |
| Package.onUse(function(api) { | |
| api.versionsFrom('1.0'); | |
| api.use([ | |
| 'rocketchat:lib' | |
| ]); | |
| api.addFiles('autoimage.js', ['server','client']); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment