From ff941b2cb186d0517ed0bee2cbc302ac81c52e39 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 21 Sep 2025 20:29:38 +0300 Subject: [PATCH] chore(react/type_widget): render math in read-only text --- .../client/src/widgets/type_widgets/text/ReadOnlyText.tsx | 8 ++++++++ .../client/src/widgets/type_widgets_old/read_only_text.ts | 4 ---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx index 8e03b4218..66f4092f5 100644 --- a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx +++ b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx @@ -12,6 +12,7 @@ import FNote from "../../../entities/fnote"; import { getLocaleById } from "../../../services/i18n"; import { getMermaidConfig } from "../../../services/mermaid"; import { loadIncludedNote, refreshIncludedNote } from "./utils"; +import { renderMathInElement } from "../../../services/math"; export default function ReadOnlyText({ note }: TypeWidgetProps) { const blob = useNoteBlob(note); @@ -25,6 +26,7 @@ export default function ReadOnlyText({ note }: TypeWidgetProps) { applyInlineMermaid(container); applyIncludedNotes(container); + applyMath(container); }, [ blob ]); // React to included note changes. @@ -86,3 +88,9 @@ function applyIncludedNotes(container: HTMLDivElement) { } } +function applyMath(container: HTMLDivElement) { + const equations = container.querySelectorAll("span.math-tex"); + for (const equation of equations) { + renderMathInElement(equation, { trust: true }); + } +} diff --git a/apps/client/src/widgets/type_widgets_old/read_only_text.ts b/apps/client/src/widgets/type_widgets_old/read_only_text.ts index 8b36c15db..2738186c5 100644 --- a/apps/client/src/widgets/type_widgets_old/read_only_text.ts +++ b/apps/client/src/widgets/type_widgets_old/read_only_text.ts @@ -37,10 +37,6 @@ export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget { this.loadReferenceLinkTitle($(el)); }); - if (this.$content.find("span.math-tex").length > 0) { - renderMathInElement(this.$content[0], { trust: true }); - } - await formatCodeBlocks(this.$content); }