Skip to content

Commit

Permalink
Merge pull request #350 from mathjax/issue2191
Browse files Browse the repository at this point in the history
Check that parent is defined before getting its metrics.  mathjax/MathJax#2191
  • Loading branch information
dpvc authored Oct 19, 2019
2 parents 8cec61b + d818153 commit d7158c1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ts/core/MathDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export interface MathDocument<N, T, D> {
* Convert a math string to the document's output format
*
* @param {string} math The math string to convert
* @params {OptionList} optoins The options for the conversion (e.g., format, ex, em, etc.)
* @params {OptionList} options The options for the conversion (e.g., format, ex, em, etc.)
* @return {MmlNode|N} The MmlNode or N node for the converted content
*/
convert(math: string, options?: OptionList): MmlNode | N;
Expand Down
13 changes: 8 additions & 5 deletions ts/handlers/html/HTMLMathItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,21 @@ export class HTMLMathItem<N, T, D> extends AbstractMathItem<N, T, D> {
*/
public removeFromDocument(restore: boolean = false) {
if (this.state() >= STATE.TYPESET) {
const adaptor = this.adaptor;
let node = this.start.node;
let math: N | T = this.adaptor.text('');
let math: N | T = adaptor.text('');
if (restore) {
let text = this.start.delim + this.math + this.end.delim;
if (this.inputJax.processStrings) {
math = this.adaptor.text(text);
math = adaptor.text(text);
} else {
const doc = this.adaptor.parse(text, 'text/html');
math = this.adaptor.firstChild(this.adaptor.body(doc));
const doc = adaptor.parse(text, 'text/html');
math = adaptor.firstChild(adaptor.body(doc));
}
}
this.adaptor.replace(math, node);
if (adaptor.parent(node)) {
adaptor.replace(math, node);
}
this.start.node = this.end.node = math;
this.start.n = this.end.n = 0;
}
Expand Down
20 changes: 13 additions & 7 deletions ts/output/common/OutputJax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import {AbstractOutputJax} from '../../core/OutputJax.js';
import {MathDocument} from '../../core/MathDocument.js';
import {MathItem, Metrics} from '../../core/MathItem.js';
import {MathItem, Metrics, STATE} from '../../core/MathItem.js';
import {MmlNode} from '../../core/MmlTree/MmlNode.js';
import {FontData, FontDataClass, CharOptions, DelimiterData, CssFontData} from './FontData.js';
import {OptionList, separateOptions} from '../../util/Options.js';
Expand Down Expand Up @@ -260,9 +260,13 @@ export abstract class CommonOutputJax<
const adaptor = this.adaptor;
const maps = this.getMetricMaps(html);
for (const math of html.math) {
const map = maps[math.display ? 1 : 0];
const {em, ex, containerWidth, lineWidth, scale} = map.get(adaptor.parent(math.start.node));
math.setMetrics(em, ex, containerWidth, lineWidth, scale);
const parent = adaptor.parent(math.start.node);
if (math.state() < STATE.METRICS && parent) {
const map = maps[math.display ? 1 : 0];
const {em, ex, containerWidth, lineWidth, scale} = map.get(parent);
math.setMetrics(em, ex, containerWidth, lineWidth, scale);
math.state(STATE.METRICS);
}
}
}

Expand Down Expand Up @@ -296,9 +300,11 @@ export abstract class CommonOutputJax<
//
for (const math of html.math) {
const node = adaptor.parent(math.start.node);
const map = domMaps[math.display? 1 : 0];
if (!map.has(node)) {
map.set(node, this.getTestElement(node, math.display));
if (node && math.state() < STATE.METRICS) {
const map = domMaps[math.display ? 1 : 0];
if (!map.has(node)) {
map.set(node, this.getTestElement(node, math.display));
}
}
}
//
Expand Down

0 comments on commit d7158c1

Please sign in to comment.