diff options
author | Simon Bartlett <simon@securitycompass.com> | 2015-04-02 14:43:29 -0400 |
---|---|---|
committer | Simon Bartlett <simon@securitycompass.com> | 2015-04-02 14:43:29 -0400 |
commit | 3bdcf6da7db41d72a60b00d16a3a6f534913c740 (patch) | |
tree | 2bce6ed6a964ae3043bf4e1a3776843170bf575b /media/js/util/message.js | |
parent | d1b5e4371925f902cc34047c150f0365d4db8bd8 (diff) | |
parent | 599597f8a80dfb91a3baf008caa3ace0eef4d43d (diff) | |
download | lets-chat-origin/try-md.zip lets-chat-origin/try-md.tar.gz lets-chat-origin/try-md.tar.bz2 |
Merge branch 'feature/md' into try-mdorigin/try-md
Diffstat (limited to 'media/js/util/message.js')
-rw-r--r-- | media/js/util/message.js | 60 |
1 files changed, 41 insertions, 19 deletions
diff --git a/media/js/util/message.js b/media/js/util/message.js index 6138bfa..158b870 100644 --- a/media/js/util/message.js +++ b/media/js/util/message.js @@ -14,7 +14,28 @@ if (typeof exports !== 'undefined') { // // Message Text Formatting // - + var markdownFormatter = window.markdownit('zero', { + html: false, + breaks: true, + linkify: true + }).enable([ + 'backticks', + 'emphasis', + 'link', + 'linkify', + 'newline', + + 'blockquote', + 'code', + 'fence', + 'list' + ]); + + function markdownFormat(text) { + return markdownFormatter + .render(text) + .replace(/<a /g, '<a target="_blank" '); + } function getBaseUrl() { var parts = window.location.pathname.split('/'); @@ -74,23 +95,21 @@ if (typeof exports !== 'undefined') { }); } - function links(text) { - var imagePattern = /^\s*((https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;'"!()]*[-A-Z0-9+&@#\/%=~_|][.](jpe?g|png|gif))\s*$/i, - linkPattern = /((https?|ftp):\/\/[-A-Z0-9+&*@#\/%?=~_|!:,.;'"!()]*[-A-Z0-9+&@#\/%=~_|])/ig; + function embeds(text) { + text = uploads(text); - if (imagePattern.test(text)) { - return text.replace(imagePattern, function(url) { - var uri = encodeURI(_.unescape(url)); - return '<a class="thumbnail" href="' + uri + - '" target="_blank"><img src="' + uri + - '" alt="Pasted Image" /></a>'; - }); - } else { - return text.replace(linkPattern, function(url) { - var uri = encodeURI(_.unescape(url)); - return '<a href="' + uri + '" target="_blank">' + url + '</a>'; - }); + var imagePattern = /^\s*((https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;'"!()]*[-A-Z0-9+&@#\/%=~_|][.](jpe?g|png|gif))\s*$/i; + + if (!text.match(imagePattern)) { + return false; } + + return text.replace(imagePattern, function(url) { + var uri = encodeURI(_.unescape(url)); + return '<a class="thumbnail" href="' + uri + + '" target="_blank"><img src="' + uri + + '" alt="Pasted Image" /></a>'; + }); } function emotes(text, data) { @@ -122,12 +141,15 @@ if (typeof exports !== 'undefined') { } exports.format = function(text, data) { + var embed = embeds(text); + if (embed) { + return embed; + } + var pipeline = [ - trim, + markdownFormat, mentions, roomLinks, - uploads, - links, emotes, replacements ]; |