markdown: Add support for spoilers.

This adds support for a "spoiler" syntax in Zulip's markdown, which
can be used to hide content that one doesn't want to be immediately
visible without a click.

We use our own spoiler block syntax inspired by Zulip's existing quote
and math block markdown extensions, rather than requiring a token on
every line, as is present in some other markdown spoiler
implementations.

Fixes #5802.

Co-authored-by: Dylan Nugent <dylnuge@gmail.com>
This commit is contained in:
Sara Gulotta
2020-04-04 16:14:34 -04:00
committed by Tim Abbott
parent 54604257e0
commit 1cb040647b
19 changed files with 383 additions and 7 deletions

View File

@@ -153,6 +153,19 @@ exports.update_elements = (content) => {
}
});
content.find('div.spoiler-header').each(function () {
// If a spoiler block has no header content, it should have a default header
// We do this client side to allow for i18n by the client
if ($.trim($(this).html()).length === 0) {
$(this).append(`<p>${i18n.t('Spoiler')}</p>`);
}
// Add the expand/collapse button to spoiler blocks
const toggle_button_html = '<a class="spoiler-button" aria-expanded="false"><span class="spoiler-arrow"></span></a>';
$(this).prepend(toggle_button_html);
});
// Display emoji (including realm emoji) as text if
// page_params.emojiset is 'text'.
if (page_params.emojiset === 'text') {