Skip to content

Commit

Permalink
Merge pull request #457 from mathjax/issue2371
Browse files Browse the repository at this point in the history
Fix error with setting startup.elements in configuration.  (mathjax/MathJax#2371)
  • Loading branch information
dpvc committed Apr 6, 2020
2 parents 48217dc + f8c4527 commit 5a527a4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
12 changes: 10 additions & 2 deletions ts/components/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand All @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions ts/components/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
Expand Down Expand Up @@ -335,7 +335,7 @@ export namespace Startup {
document.reset();
return mathjax.handleRetriesFor(() => {
document.render();
})
});
};
MathJax.typesetClear = () => document.clear();
};
Expand Down
7 changes: 2 additions & 5 deletions ts/core/MathDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,7 @@ export abstract class AbstractMathDocument<N, T, D> implements MathDocument<N, T
doc.typesetError(math, err);
},
renderActions: expandable({
find: [STATE.FINDMATH, (document: MathDocument<any, any, any>) => {
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],
Expand Down Expand Up @@ -827,4 +824,4 @@ export interface MathDocumentConstructor<D extends MathDocument<any, any, any>>
OPTIONS: OptionList;
ProcessBits: typeof BitField;
new (...args: any[]): D;
};
}
2 changes: 1 addition & 1 deletion ts/handlers/html/HTMLDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class HTMLDocument<N, T, D> extends AbstractMathDocument<N, T, D> {
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<N, T>];
for (const jax of this.inputJax) {
Expand Down
2 changes: 1 addition & 1 deletion ts/output/common/OutputJax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,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,
Expand Down

0 comments on commit 5a527a4

Please sign in to comment.