Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(react/type_widget): render math in read-only text
Elian Doranff941b2cb186
diff --git a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsxindex 8e03b4218d..66f4092f51 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.tsindex 8b36c15db4..2738186c50 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);}