mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
Use backend markdown processor in message preview.
[tweaked by tabbott to add comment and fetch the authoritative rendering from the backend unconditionally] Fixes #1834.
This commit is contained in:
@@ -1004,7 +1004,6 @@ $(function () {
|
|||||||
$("#compose").on("click", "#markdown_preview", function (e) {
|
$("#compose").on("click", "#markdown_preview", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var message = $("#new_message_content").val();
|
var message = $("#new_message_content").val();
|
||||||
var preview = echo.apply_markdown(message);
|
|
||||||
$("#new_message_content").hide();
|
$("#new_message_content").hide();
|
||||||
$("#markdown_preview").hide();
|
$("#markdown_preview").hide();
|
||||||
$("#undo_markdown_preview").show();
|
$("#undo_markdown_preview").show();
|
||||||
@@ -1013,7 +1012,29 @@ $(function () {
|
|||||||
if (message.length === 0) {
|
if (message.length === 0) {
|
||||||
$("#preview_message_area").html(i18n.t("Nothing to preview"));
|
$("#preview_message_area").html(i18n.t("Nothing to preview"));
|
||||||
} else {
|
} else {
|
||||||
$("#preview_message_area").html(preview);
|
if (echo.contains_bugdown(message)) {
|
||||||
|
$("#preview_message_area").html(i18n.t("Loading preview..."));
|
||||||
|
} else {
|
||||||
|
// For messages that don't appear to contain
|
||||||
|
// bugdown-specific syntax not present in our
|
||||||
|
// marked.js frontend processor, we render using the
|
||||||
|
// frontend markdown processor message (but still
|
||||||
|
// render server-side to ensure the preview is
|
||||||
|
// accurate; if the `echo.contains_bugdown` logic is
|
||||||
|
// incorrect wrong, users will see a brief flicker).
|
||||||
|
$("#preview_message_area").html(echo.apply_markdown(message));
|
||||||
|
}
|
||||||
|
channel.get({
|
||||||
|
url: '/json/messages/render',
|
||||||
|
idempotent: true,
|
||||||
|
data: {content: message},
|
||||||
|
success: function (response_data) {
|
||||||
|
$("#preview_message_area").html(response_data.rendered);
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
|
$("#preview_message_area").html(i18n.t("Failed to generate preview"));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user