around our code blocks instead a codehilite , and disable class-specific highlighting
// We special-case the 'quote' language and output a blockquote
r.code = function (code, lang) {
if (lang === 'quote') {
return '\n' + escape(code, true) + '
\n
\n\n\n';
}
return ''
+ escape(code, true)
+ '\n
\n\n\n';
};
// Our links have title= and target=_blank
r.link = function (href, title, text) {
title = title || href;
var out = '' + text + '';
return out;
};
// Put a newline after a
in the generated HTML to match bugdown
r.br = function () {
return '
\n';
};
// Disable ordered lists
// We used GFM + tables, so replace the list start regex for that ruleset
// We remove the |[\d+]\. that matches the numbering in a numbered list
marked.Lexer.rules.tables.list = /^( *)((?:\*)) [\s\S]+?(?:\n+(?=(?: *[\-*_]){3,} *(?:\n+|$))|\n{2,}(?! )(?!\1(?:\*) )\n*|\s*$)/;
// Disable headings
disable_markdown_regex(marked.Lexer.rules.tables, 'heading');
disable_markdown_regex(marked.Lexer.rules.tables, 'lheading');
// Disable __strong__, all
marked.InlineLexer.rules.zulip.strong = /^\*\*([\s\S]+?)\*\*(?!\*)/;
disable_markdown_regex(marked.InlineLexer.rules.zulip, 'em');
disable_markdown_regex(marked.InlineLexer.rules.zulip, 'del');
// Disable autolink as (a) it is not used in our backend and (b) it interferes with @mentions
disable_markdown_regex(marked.InlineLexer.rules.zulip, 'autolink');
exports.set_realm_filters(page_params.realm_filters);
marked.setOptions({
gfm: true,
tables: true,
breaks: true,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: false,
zulip: true,
emojiHandler: handleEmoji,
userMentionHandler: handleUserMentions,
realmFilterHandler: handleRealmFilter,
renderer: r
});
function on_failed_action(action, callback) {
$("#main_div").on("click", "." + action + "-failed-message", function (e) {
e.stopPropagation();
popovers.hide_all();
var row = $(this).closest(".message_row");
var message_id = rows.id(row);
// Message should be waiting for ack and only have a local id,
// otherwise send would not have failed
var message = waiting_for_ack[message_id];
if (message === undefined) {
blueslip.warning("Got resend or retry on failure request but did not find message in ack list " + message_id);
return;
}
callback(message, row);
});
}
on_failed_action('remove', abort_message);
on_failed_action('refresh', resend_message);
on_failed_action('edit', edit_failed_message);
$(document).on('home_view_loaded.zulip', function () {
home_view_loaded = true;
});
});
$(document).on('socket_loaded_requests.zulip', function (event, data) {
var msgs_to_insert = [];
var next_local_id = get_next_local_id();
_.each(data.requests, function (socket_msg, key) {
var msg = socket_msg.msg;
// Check for any message objects, then insert them locally
if (msg.stream === undefined || msg.local_id === undefined) {
return;
}
msg.local_id = next_local_id;
msg.queue_id = page_params.event_queue_id;
next_local_id = truncate_precision(next_local_id + 0.01);
msgs_to_insert.push(msg);
});
function echo_pending_messages() {
_.each(msgs_to_insert, function (msg) {
insert_local_message(msg, msg.local_id);
});
}
if (home_view_loaded) {
echo_pending_messages();
} else {
$(document).on('home_view_loaded.zulip', function () {
echo_pending_messages();
});
}
});
return exports;
}());
if (typeof module !== 'undefined') {
module.exports = echo;
}