Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that parent is defined before getting its metrics. mathjax/MathJax#2191 #350

Merged
merged 4 commits into from
Oct 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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