chore(react/type_widget): render math in read-only text

This commit is contained in:
Elian Doran 2025-09-21 20:29:38 +03:00
parent a8007b9063
commit ff941b2cb1
No known key found for this signature in database
2 changed files with 8 additions and 4 deletions

View File

@ -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 });
}
}

View File

@ -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);
}