Skip to content

Commit d790c74

Browse files
committed
Remove munderover elements that have been cleaned. (mathjax/MathJax#2691)
1 parent 89c4c4c commit d790c74

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

ts/input/tex/FilterUtil.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ namespace FilterUtil {
8686
* @param {ParseOptions} data The parse options.
8787
*/
8888
export let combineRelations = function(arg: {data: ParseOptions}) {
89+
const remove: MmlNode[] = [];
8990
for (let mo of arg.data.getList('mo')) {
9091
if (mo.getProperty('relationsCombined') || !mo.parent ||
9192
(mo.parent && !NodeUtil.isType(mo.parent, 'mrow')) ||
@@ -111,6 +112,7 @@ namespace FilterUtil {
111112
_copyExplicit(['stretchy', 'rspace'], mo, m2);
112113
NodeUtil.setProperties(mo, m2.getAllProperties());
113114
children.splice(next, 1);
115+
remove.push(m2);
114116
m2.parent = null;
115117
m2.setProperty('relationsCombined', true);
116118
} else {
@@ -127,7 +129,8 @@ namespace FilterUtil {
127129
}
128130
}
129131
mo.attributes.setInherited('form', (mo as MmlMo).getForms()[0]);
130-
}
132+
}
133+
arg.data.removeFromList('mo', remove);
131134
};
132135

133136

@@ -191,6 +194,7 @@ namespace FilterUtil {
191194
* @param {string} up String representing the upper part.
192195
*/
193196
let _cleanSubSup = function(options: ParseOptions, low: string, up: string) {
197+
const remove: MmlNode[] = [];
194198
for (let mml of options.getList('m' + low + up) as any[]) {
195199
const children = mml.childNodes;
196200
if (children[mml[low]] && children[mml[up]]) {
@@ -206,7 +210,9 @@ namespace FilterUtil {
206210
} else {
207211
options.root = newNode;
208212
}
213+
remove.push(mml);
209214
}
215+
options.removeFromList('m' + low + up, remove);
210216
};
211217

212218

@@ -235,8 +241,9 @@ namespace FilterUtil {
235241
* @param {ParseOptions} data The parse options.
236242
*/
237243
let _moveLimits = function (options: ParseOptions, underover: string, subsup: string) {
244+
const remove: MmlNode[] = [];
238245
for (const mml of options.getList(underover)) {
239-
if (mml.attributes.get('displaystyle')) {
246+
if (mml.attributes.get('displaystyle') || mml.getProperty('removed')) {
240247
continue;
241248
}
242249
const base = mml.childNodes[(mml as any).base] as MmlNode;
@@ -249,8 +256,10 @@ namespace FilterUtil {
249256
} else {
250257
options.root = node;
251258
}
259+
remove.push(mml);
252260
}
253261
}
262+
options.removeFromList(underover, remove);
254263
};
255264

256265
/**

ts/input/tex/ParseOptions.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,24 @@ export default class ParseOptions {
199199
}
200200

201201

202+
/**
203+
* Remove a list of nodes from a saved list (e.g., when a filter removes the
204+
* node from the DOM, like for munderover => munder).
205+
*
206+
* @param {string} property The property from which to remove nodes.
207+
* @param {MmlNode[]} nodes The nodes to remove.
208+
*/
209+
public removeFromList(property: string, nodes: MmlNode[]) {
210+
const list = this.nodeLists[property] || [];
211+
for (const node of nodes) {
212+
const i = list.indexOf(node);
213+
if (i >= 0) {
214+
list.splice(i, 1);
215+
}
216+
}
217+
}
218+
219+
202220
/**
203221
* Tests if the node is in the tree spanned by the current root node.
204222
* @param {MmlNode} node The node to test.

0 commit comments

Comments
 (0)