From f8c4527b8484a8e2c8ba96aa68fde5c66deed658 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Thu, 19 Mar 2020 12:45:58 -0400 Subject: [PATCH] Fix error with setting startup.elements in configuration. (mathjax/MathJax#2371) --- ts/components/global.ts | 12 ++++++++++-- ts/components/startup.ts | 4 ++-- ts/core/MathDocument.ts | 7 ++----- ts/handlers/html/HTMLDocument.ts | 2 +- ts/output/common/OutputJax.ts | 2 +- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/ts/components/global.ts b/ts/components/global.ts index b00936449..684ec28e5 100644 --- a/ts/components/global.ts +++ b/ts/components/global.ts @@ -45,6 +45,14 @@ export interface MathJaxObject { declare const global: {MathJax: MathJaxObject | MathJaxConfig}; +/** + * @param {any} x An item to test if it is an object + * @return {boolean} True if the item is a non-null object + */ +export function isObject(x: any) { + return typeof x === 'object' && x !== null; +} + /** * Combine user-produced configuration with existing defaults. Values * from src will replace those in dst. @@ -56,7 +64,7 @@ declare const global: {MathJax: MathJaxObject | MathJaxConfig}; export function combineConfig(dst: any, src: any) { for (const id of Object.keys(src)) { if (id === '__esModule') continue; - if (typeof dst[id] === 'object' && typeof src[id] === 'object' && + if (isObject(dst[id]) && isObject(src[id]) && !(src[id] instanceof Promise) /* needed for IE polyfill */) { combineConfig(dst[id], src[id]); } else if (src[id] !== null && src[id] !== undefined) { @@ -82,7 +90,7 @@ export function combineDefaults(dst: any, name: string, src: any) { } dst = dst[name]; for (const id of Object.keys(src)) { - if (typeof dst[id] === 'object' && typeof src[id] === 'object') { + if (isObject(dst[id]) && isObject(src[id])) { combineDefaults(dst, id, src[id]); } else if (dst[id] == null && src[id] != null) { dst[id] = src[id]; diff --git a/ts/components/startup.ts b/ts/components/startup.ts index c23447b21..e86ecd39a 100644 --- a/ts/components/startup.ts +++ b/ts/components/startup.ts @@ -268,7 +268,7 @@ export namespace Startup { * Setting Mathjax.startup.pageReady in the configuration will override this. */ export function defaultPageReady() { - return (CONFIG.typeset && MathJax.typesetPromise ? MathJax.typesetPromise() : null); + return (CONFIG.typeset && MathJax.typesetPromise ? MathJax.typesetPromise(CONFIG.elements) : null); }; /** @@ -335,7 +335,7 @@ export namespace Startup { document.reset(); return mathjax.handleRetriesFor(() => { document.render(); - }) + }); }; MathJax.typesetClear = () => document.clear(); }; diff --git a/ts/core/MathDocument.ts b/ts/core/MathDocument.ts index 0bbab6a81..47cd03098 100644 --- a/ts/core/MathDocument.ts +++ b/ts/core/MathDocument.ts @@ -509,10 +509,7 @@ export abstract class AbstractMathDocument implements MathDocument) => { - const elements = document.options.elements; - document.findMath(elements ? {elements} : {}); - }, () => {}, false], + find: [STATE.FINDMATH, 'findMath', '', false], compile: [STATE.COMPILED], metrics: [STATE.METRICS, 'getMetrics', '', false], typeset: [STATE.TYPESET], @@ -827,4 +824,4 @@ export interface MathDocumentConstructor> OPTIONS: OptionList; ProcessBits: typeof BitField; new (...args: any[]): D; -}; +} diff --git a/ts/handlers/html/HTMLDocument.ts b/ts/handlers/html/HTMLDocument.ts index d41309750..34f946630 100644 --- a/ts/handlers/html/HTMLDocument.ts +++ b/ts/handlers/html/HTMLDocument.ts @@ -145,7 +145,7 @@ export class HTMLDocument extends AbstractMathDocument { public findMath(options: OptionList) { if (!this.processed.isSet('findMath')) { this.adaptor.document = this.document; - options = userOptions({elements: [this.adaptor.body(this.document)]}, options); + options = userOptions({elements: this.options.elements || [this.adaptor.body(this.document)]}, options); for (const container of this.adaptor.getElements(options['elements'], this.document)) { let [strings, nodes] = [null, null] as [string[], HTMLNodeArray]; for (const jax of this.inputJax) { diff --git a/ts/output/common/OutputJax.ts b/ts/output/common/OutputJax.ts index 2f85c5945..846492f8e 100644 --- a/ts/output/common/OutputJax.ts +++ b/ts/output/common/OutputJax.ts @@ -147,7 +147,7 @@ export abstract class CommonOutputJax< * Get the cssStyle and font objects * * @param {OptionList} options The configuration options - * @param(FontDataClass} defaultFont The default FontData constructor + * @param {FontDataClass} defaultFont The default FontData constructor * @constructor */ constructor(options: OptionList = null,