mirror of https://github.com/zulip/zulip.git
desktop_notification: Fix bad rendering of math formulas.
Earlier, for the desktop notifications having latex math like "$$1 \oplus 0 = 1$$, the notification had the math included multiple times. This commit fixes the incorrect behavior by replacing the KaTeX with the raw LaTeX source. Fixes #25289.
This commit is contained in:
parent
6f3b25d749
commit
9c5cfe83ba
|
@ -19,6 +19,7 @@ function get_notification_content(message) {
|
|||
// Convert the content to plain text, replacing emoji with their alt text
|
||||
const $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 (
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue