Add support for !avatar syntax in echo.js.

This commit is contained in:
hackerkid
2016-10-19 20:19:53 +05:30
committed by Tim Abbott
parent 67adf570e7
commit 95b5ac1d5d
4 changed files with 31 additions and 6 deletions

View File

@@ -470,6 +470,7 @@ var inline = {
emoji: noop,
unicodeemoji: noop,
usermention: noop,
avatar: noop,
realm_filters: [],
text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
};
@@ -528,6 +529,7 @@ inline.zulip = merge({}, inline.breaks, {
emoji: /^:([A-Za-z0-9_\-\+]+?):/,
unicodeemoji: /^(\ud83c[\udf00-\udfff]|\ud83d[\udc00-\ude4f]|\ud83d[\ude80-\udeff])/,
usermention: /^(@\*\*([^\*]+)?\*\*)/m,
avatar: /^!avatar\(([^)]+)\)/,
realm_filters: [],
text: replace(inline.breaks.text)
('|', '|(\ud83c[\udf00-\udfff]|\ud83d[\udc00-\ude4f]|\ud83d[\ude80-\udeff])|')
@@ -752,6 +754,13 @@ InlineLexer.prototype.output = function(src) {
continue;
}
// user avatar
if (cap = this.rules.avatar.exec(src)) {
src = src.substring(cap[0].length);
out += this.userAvatar(cap[1]);
continue;
}
// text
if (cap = this.rules.text.exec(src)) {
src = src.substring(cap[0].length);
@@ -796,6 +805,13 @@ InlineLexer.prototype.unicodeEmoji = function (name) {
return this.options.unicodeEmojiHandler(name);
};
InlineLexer.prototype.userAvatar = function (email) {
if (typeof this.options.avatarHandler !== 'function')
return '!avatar(' + email + ')';
return this.options.avatarHandler(email);
};
InlineLexer.prototype.realm_filter = function (filter, matches, orig) {
if (typeof this.options.realmFilterHandler !== 'function')
return;
@@ -1369,6 +1385,7 @@ marked.defaults = {
gfm: true,
emoji: false,
unicodeemoji: false,
avatar: false,
tables: true,
breaks: false,
pedantic: false,