Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
desktop_notification: Fix bad rendering of math formulas.
Prakhar Pratyush9c5cfe83baec
diff --git a/web/src/message_notifications.js b/web/src/message_notifications.jsindex f9f6bde8151..b40da13d724 100644--- a/web/src/message_notifications.js+++ b/web/src/message_notifications.js@@ -19,6 +19,7 @@ function get_notification_content(message) {// Convert the content to plain text, replacing emoji with their alt textconst $content = $("<div>").html(message.content);ui_util.replace_emoji_with_text($content);+ ui_util.change_katex_to_raw_latex($content);spoilers.hide_spoilers_in_notification($content);if (diff --git a/web/src/ui_util.ts b/web/src/ui_util.tsindex fb6efba3ace..c1f3f2428e3 100644--- a/web/src/ui_util.ts+++ b/web/src/ui_util.ts@@ -30,6 +30,20 @@ export function replace_emoji_with_text($element: JQuery): void {});}+export function change_katex_to_raw_latex($element: JQuery): void {+ // Find all the span elements with the class "katex"+ $element.find("span.katex").each(function () {+ // Find the text within the <annotation> tag+ const latex_text = $(this).find('annotation[encoding="application/x-tex"]').text();++ // Create a new <span> element with the raw latex wrapped in $$+ const $latex_span = $("<span>").text("$$" + latex_text + "$$");++ // Replace the current .katex element with the new <span> containing the text+ $(this).replaceWith($latex_span);+ });+}+export function blur_active_element(): void {// this blurs anything that may perhaps be actively focused on.if (document.activeElement instanceof HTMLElement) {diff --git a/web/tests/notifications.test.js b/web/tests/notifications.test.jsindex 47590cd2fd2..15bc3184631 100644--- a/web/tests/notifications.test.js+++ b/web/tests/notifications.test.js@@ -340,6 +340,7 @@ test("message_is_notifiable", () => {test("basic_notifications", () => {$("<div>").set_find_results(".emoji", {replaceWith() {}});+ $("<div>").set_find_results("span.katex", {each() {}});let n; // Object for storing all notification data for assertions.let last_closed_message_id = null;