Files
zulip/static/js/echo.js
Leo Franchi 0b2ba855f9 Add helper for rough determination of markdown client-side
(imported from commit 3b6439f54e55fbca0f586392d1a0add4d7f694b8)
2014-01-23 16:28:54 -05:00

36 lines
1.3 KiB
JavaScript

var echo = (function () {
var exports = {};
// Regexes that match some of our common bugdown markup
var bugdown_re = [
/(?::[^:\s]+:)(?!\w)/, // Emoji
// Inline image previews, check for contiguous chars ending in image suffix
// To keep the below regexes simple, split them out for the end-of-message case
/[^\s]*(?:\.bmp|\.gif|\.jpg|\.jpeg|\.png|\.webp)\s+/m,
/[^\s]*(?:\.bmp|\.gif|\.jpg|\.jpeg|\.png|\.webp)$/m,
// Twitter and youtube links are given previews
/[^\s]*(?:twitter|youtube).com\/[^\s]*/,
// Gravatars are inlined as well
/!avatar\([^)]+\)/,
/!gravatar\([^)]+\)/,
// User mentions
/\s+@\*\*[^\*]+\*\*/m
];
exports.contains_bugdown = function contains_bugdown(content) {
// Try to guess whether or not a message has bugdown in it
// If it doesn't, we can immediately render it client-side
var markedup = _.find(bugdown_re, function (re) {
return re.test(content);
});
return markedup !== undefined;
};
return exports;
}());
if (typeof module !== 'undefined') {
module.exports = echo;
}