MOBILE-4672 mathjax: Fix some equations not displayed in quiz

For some reason, if we tell MathJax to render an equation for an element that isn't in the DOM, for some equations it fails and displays the error message (which is an exclamation mark). If we want to be sure the equation is rendered properly we need to wait for the element to be in the DOM.
main
Dani Palou 2024-10-07 16:16:10 +02:00
parent 325aca7536
commit 341d1bc6d4
1 changed files with 5 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import { CoreEvents } from '@singletons/events';
import { CoreSite } from '@classes/sites/site'; import { CoreSite } from '@classes/sites/site';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreWait } from '@singletons/wait'; import { CoreWait } from '@singletons/wait';
import { CoreDom } from '@singletons/dom';
/** /**
* Handler to support the MathJax filter. * Handler to support the MathJax filter.
@ -177,6 +178,10 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan
): Promise<void> { ): Promise<void> {
await this.waitForReady(); await this.waitForReady();
// Make sure the element is in DOM, otherwise some equations don't work.
// Automatically timeout the promise after a certain time, we don't want to wait forever.
await CoreUtils.ignoreErrors(CoreUtils.timeoutPromise(CoreDom.waitToBeInDOM(container), 15000));
await this.window.M!.filter_mathjaxloader!.typeset(container); await this.window.M!.filter_mathjaxloader!.typeset(container);
} }