Skip to content

Commit 3c40dd9

Browse files
committed
Add copyNode() to ParseUtil and make it save the the nodes in the node lists. Keep track of extra lists that nodes are in so that copies can save to those lists as well.
1 parent 38e067d commit 3c40dd9

5 files changed

Lines changed: 27 additions & 4 deletions

File tree

ts/core/MmlTree/MmlNode.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ export abstract class AbstractMmlNode extends AbstractNode implements MmlNode {
371371
for (const child of children) {
372372
if (child) {
373373
node.appendChild(child.copy() as MmlNode);
374+
} else {
375+
node.childNodes.push(null);
374376
}
375377
}
376378
}

ts/input/tex/ParseOptions.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import StackItemFactory from './StackItemFactory.js';
2626
import {Tags} from './Tags.js';
2727
import {SubHandlers} from './MapHandler.js';
2828
import {NodeFactory} from './NodeFactory.js';
29+
import NodeUtil from './NodeUtil.js';
2930
import {MmlNode} from '../../core/MmlTree/MmlNode.js';
3031
import TexParser from './TexParser.js';
3132
import {defaultOptions, OptionList} from '../../util/Options.js';
@@ -173,6 +174,14 @@ export default class ParseOptions {
173174
list = this.nodeLists[property] = [];
174175
}
175176
list.push(node);
177+
if (node.kind !== property) {
178+
//
179+
// If the list is not just for its kind, record that it is in this list
180+
// so that if it is copied, the copy can also be added to the list.
181+
//
182+
let lists = (NodeUtil.getProperty(node, 'in-lists') as string || '').split(',').concat(property).join(',');
183+
NodeUtil.setProperty(node, 'in-lists', lists);
184+
}
176185
}
177186

178187

ts/input/tex/ParseUtil.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,18 @@ namespace ParseUtil {
469469
parser.stack.global.eqnenv = true;
470470
}
471471

472+
export function copyNode(node: MmlNode, parser: TexParser): MmlNode {
473+
const tree = node.copy() as MmlNode;
474+
const options = parser.configuration;
475+
tree.walkTree((n: MmlNode) => {
476+
options.addNode(n.kind, n);
477+
const lists = (n.getProperty('in-lists') as string || '').split(/,/);
478+
for (const list of lists) {
479+
options.addNode(list, n);
480+
}
481+
});
482+
return tree;
483+
}
472484

473485
/**
474486
* This is a placeholder for future security filtering of attributes.

ts/input/tex/cases/CasesConfiguration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export const CasesMethods = {
9393
parser.Push(parser.itemFactory.create('end').setProperty('name', begin.getName())); // finish eqnarray
9494
const cases = parser.stack.Top();
9595
const table = cases.Last as MmlMtable;
96-
const original = table.copy() as MmlMtable;
96+
const original = ParseUtil.copyNode(table, parser) as MmlMtable;
9797
const left = cases.getProperty('left');
9898
EmpheqUtil.left(table, original, left + '\\empheqlbrace\\,', parser, 'numcases-left');
9999
parser.Push(parser.itemFactory.create('end').setProperty('name', begin.getName()));

ts/input/tex/empheq/EmpheqUtil.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export const EmpheqUtil = {
111111
* @return {MmlNode} The resulting mphantom element.
112112
*/
113113
topRowTable(original: MmlMtable, parser: TexParser): MmlNode {
114-
const table = original.copy();
114+
const table = ParseUtil.copyNode(original, parser);
115115
table.setChildren(table.childNodes.slice(0, 1));
116116
table.attributes.set('align', 'baseline 1');
117117
return original.factory.create('mphantom', {}, [parser.create('node', 'mpadded', [table], {width: 0})]);
@@ -130,7 +130,7 @@ export const EmpheqUtil = {
130130
rowspanCell(mtd: MmlMtd, tex: string, table: MmlMtable, parser: TexParser, env: string) {
131131
mtd.appendChild(
132132
parser.create('node', 'mpadded', [
133-
this.cellBlock(tex, table.copy(), parser, env),
133+
this.cellBlock(tex, ParseUtil.copyNode(table, parser), parser, env),
134134
this.topRowTable(table, parser)
135135
], {height: 0, depth: 0, voffset: 'height'})
136136
);
@@ -197,7 +197,7 @@ export const EmpheqUtil = {
197197
const right = empheq.getProperty('right');
198198
if (left || right) {
199199
const table = empheq.Last;
200-
const original = table.copy();
200+
const original = ParseUtil.copyNode(table, parser);
201201
if (left) this.left(table, original, left, parser);
202202
if (right) this.right(table, original, right, parser);
203203
}

0 commit comments

Comments
 (0)