mathpix-markdown-it 1.0.90 → 1.0.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/.idea/workspace.xml +467 -1829
  2. package/README.md +2 -0
  3. package/es5/bundle.js +1 -1
  4. package/es5/context-menu.js +1 -1
  5. package/es5/index.js +1 -1
  6. package/lib/contex-menu/menu/consts.d.ts +1 -0
  7. package/lib/contex-menu/menu/consts.js +2 -0
  8. package/lib/contex-menu/menu/consts.js.map +1 -1
  9. package/lib/contex-menu/menu/menu-item-actions.js +1 -1
  10. package/lib/contex-menu/menu/menu-item-actions.js.map +1 -1
  11. package/lib/contex-menu/menu/menu-item.js +4 -0
  12. package/lib/contex-menu/menu/menu-item.js.map +1 -1
  13. package/lib/helpers/parse-mmd-element.js +3 -3
  14. package/lib/helpers/parse-mmd-element.js.map +1 -1
  15. package/lib/markdown/common/consts.d.ts +5 -0
  16. package/lib/markdown/common/consts.js +7 -2
  17. package/lib/markdown/common/consts.js.map +1 -1
  18. package/lib/markdown/common/csv.d.ts +2 -0
  19. package/lib/markdown/common/csv.js +36 -0
  20. package/lib/markdown/common/csv.js.map +1 -0
  21. package/lib/markdown/md-block-rule/begin-tabular/index.d.ts +1 -0
  22. package/lib/markdown/md-block-rule/begin-tabular/index.js +1 -0
  23. package/lib/markdown/md-block-rule/begin-tabular/index.js.map +1 -1
  24. package/lib/markdown/md-block-rule/begin-tabular/tabular-td.js +4 -1
  25. package/lib/markdown/md-block-rule/begin-tabular/tabular-td.js.map +1 -1
  26. package/lib/markdown/md-renderer-rules/render-tabular.js +39 -8
  27. package/lib/markdown/md-renderer-rules/render-tabular.js.map +1 -1
  28. package/lib/markdown/mdPluginRaw.js +7 -3
  29. package/lib/markdown/mdPluginRaw.js.map +1 -1
  30. package/lib/mathjax/index.d.ts +3 -1
  31. package/lib/mathjax/index.js +31 -43
  32. package/lib/mathjax/index.js.map +1 -1
  33. package/lib/mathjax/mathjax.js +1 -1
  34. package/lib/mathjax/mathjax.js.map +1 -1
  35. package/lib/mathjax/serialized-ascii/common.d.ts +6 -0
  36. package/lib/mathjax/serialized-ascii/common.js +16 -0
  37. package/lib/mathjax/serialized-ascii/common.js.map +1 -0
  38. package/lib/mathjax/serialized-ascii/handlers.d.ts +2 -1
  39. package/lib/mathjax/serialized-ascii/handlers.js +525 -244
  40. package/lib/mathjax/serialized-ascii/handlers.js.map +1 -1
  41. package/lib/mathjax/serialized-ascii/index.d.ts +10 -9
  42. package/lib/mathjax/serialized-ascii/index.js +137 -60
  43. package/lib/mathjax/serialized-ascii/index.js.map +1 -1
  44. package/lib/mathpix-markdown-model/index.d.ts +7 -1
  45. package/lib/mathpix-markdown-model/index.js.map +1 -1
  46. package/package.json +1 -1
@@ -5,6 +5,7 @@ var tslib_1 = require("tslib");
5
5
  var MmlNode_1 = require("mathjax-full/js/core/MmlTree/MmlNode");
6
6
  var helperA_1 = require("./helperA");
7
7
  var consts_1 = require("../../helpers/consts");
8
+ var common_1 = require("./common");
8
9
  var regW = /^\w/;
9
10
  var isFirstChild = function (node) {
10
11
  return node.parent && node.parent.childNodes[0] && node.parent.childNodes[0] === node;
@@ -12,7 +13,7 @@ var isFirstChild = function (node) {
12
13
  var isLastChild = function (node) {
13
14
  return node.parent && node.parent.childNodes && node.parent.childNodes[node.parent.childNodes.length - 1] === node;
14
15
  };
15
- var needFirstSpase = function (node) {
16
+ var needFirstSpace = function (node) {
16
17
  try {
17
18
  if (isFirstChild(node)) {
18
19
  return false;
@@ -33,7 +34,7 @@ var needFirstSpase = function (node) {
33
34
  return false;
34
35
  }
35
36
  };
36
- var needLastSpase = function (node) {
37
+ var needLastSpace = function (node) {
37
38
  var haveSpace = false;
38
39
  try {
39
40
  if (node.parent.kind === "msubsup") {
@@ -168,7 +169,7 @@ exports.FindSymbolToAM = function (tag, output, atr) {
168
169
  }
169
170
  return tags ? tags.input : '';
170
171
  };
171
- var getChilrenText = function (node) {
172
+ var getChildrenText = function (node) {
172
173
  var text = '';
173
174
  try {
174
175
  node.childNodes.forEach(function (child) {
@@ -188,7 +189,11 @@ exports.getAttributes = function (node) {
188
189
  };
189
190
  var menclose = function (handlerApi) {
190
191
  return function (node, serialize) {
191
- var mml = '';
192
+ var res = {
193
+ ascii: '',
194
+ ascii_tsv: '',
195
+ ascii_csv: '',
196
+ };
192
197
  try {
193
198
  var atr = exports.getAttributes(node);
194
199
  var isLeft = false;
@@ -197,17 +202,18 @@ var menclose = function (handlerApi) {
197
202
  isLeft = atr.notation.toString().indexOf('left') > -1;
198
203
  isRight = atr.notation.toString().indexOf('right') > -1;
199
204
  }
200
- mml += isLeft ? '[' : '';
201
- mml += handlerApi.handleAll(node, serialize);
205
+ res = common_1.AddToAsciiData(res, [isLeft ? '[' : '']);
206
+ var data = handlerApi.handleAll(node, serialize);
207
+ res = common_1.AddToAsciiData(res, [data.ascii, data.ascii_tsv, data.ascii_csv]);
202
208
  if (atr && atr.lcm) {
203
- mml += '';
209
+ res = common_1.AddToAsciiData(res, ['']);
204
210
  }
205
- mml += isRight ? ']' : '';
206
- return mml;
211
+ res = common_1.AddToAsciiData(res, [isRight ? ']' : '']);
212
+ return res;
207
213
  }
208
214
  catch (e) {
209
215
  console.error('mml => menclose =>', e);
210
- return mml;
216
+ return res;
211
217
  }
212
218
  };
213
219
  };
@@ -230,21 +236,21 @@ var getDataForVerticalMath = function (serialize, node, rowNumber) {
230
236
  /** The element is wrapped in curly braces:
231
237
  * e.g. {\times 1}*/
232
238
  if (child.isKind('inferredMrow') || child.isKind('TeXAtom')) {
233
- var data = getDataForVerticalMath(serialize, child, rowNumber);
234
- if (!data.collChildrenCanBeVerticalMath) {
239
+ var data_1 = getDataForVerticalMath(serialize, child, rowNumber);
240
+ if (!data_1.collChildrenCanBeVerticalMath) {
235
241
  res.collChildrenCanBeVerticalMath = false;
236
242
  }
237
- if (data.startedFromMathOperation) {
243
+ if (data_1.startedFromMathOperation) {
238
244
  res.startedFromMathOperation = true;
239
245
  }
240
- if (data.mathOperation) {
241
- res.mathOperation = data.mathOperation;
246
+ if (data_1.mathOperation) {
247
+ res.mathOperation = data_1.mathOperation;
242
248
  }
243
- res.mmlCollVerticalMath += data.mmlCollVerticalMath;
249
+ res.mmlCollVerticalMath += data_1.mmlCollVerticalMath;
244
250
  continue;
245
251
  }
246
- var mmlChild = serialize.visitNode(child, '');
247
- var text = getChilrenText(child);
252
+ var data = serialize.visitNode(child, '');
253
+ var text = getChildrenText(child);
248
254
  if (child.kind === 'mo') {
249
255
  var symbolType = exports.getSymbolType('mo', text);
250
256
  if (symbolType === helperA_1.eSymbolType.logical
@@ -255,25 +261,27 @@ var getDataForVerticalMath = function (serialize, node, rowNumber) {
255
261
  }
256
262
  if (!child.isKind('mstyle')) {
257
263
  if (k === 0 && child.kind === 'mo' && rowNumber > 0) {
258
- var text_1 = getChilrenText(child);
264
+ var text_1 = getChildrenText(child);
259
265
  if (text_1 === '+' || text_1 === '-'
260
266
  || text_1 === '\u2212' //"-"
261
267
  || text_1 === '\u00D7' //times
262
268
  || text_1 === '\u00F7' //div
263
269
  ) {
264
- res.mathOperation = mmlChild;
270
+ res.mathOperation = data.ascii;
265
271
  res.startedFromMathOperation = true;
266
272
  }
267
273
  }
268
- res.mmlCollVerticalMath += mmlChild === '","' ? ',' : mmlChild;
274
+ res.mmlCollVerticalMath += data.ascii === '","' ? ',' : data.ascii;
269
275
  }
270
276
  }
271
277
  return res;
272
278
  };
273
279
  var mtable = function () {
274
280
  return function (node, serialize) {
275
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
281
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
276
282
  var mml = '';
283
+ var mml_tsv = '';
284
+ var mml_csv = '';
277
285
  try {
278
286
  /** MathJax: <mrow> came from \left...\right
279
287
  * so treat as subexpression (TeX class INNER). */
@@ -282,18 +290,20 @@ var mtable = function () {
282
290
  var countRow = node.childNodes.length;
283
291
  var toTsv = serialize.options.tableToTsv && !serialize.options.isSubTable
284
292
  && (((_c = node.Parent) === null || _c === void 0 ? void 0 : _c.kind) === 'math' || (parentIsMenclose && ((_d = node.Parent.Parent) === null || _d === void 0 ? void 0 : _d.kind) === 'math'));
285
- node.attributes.setInherited('toTsv', toTsv);
293
+ var toCsv = (serialize.options.tableToCsv || serialize.options.tableToCsv) && !serialize.options.isSubTable
294
+ && (((_e = node.Parent) === null || _e === void 0 ? void 0 : _e.kind) === 'math' || (parentIsMenclose && ((_f = node.Parent.Parent) === null || _f === void 0 ? void 0 : _f.kind) === 'math'));
295
+ node.attributes.setInherited('toCsv', toCsv);
286
296
  var columnAlign = node.attributes.get('columnalign');
287
297
  var arrRowLines = node.attributes.isSet('rowlines') ? node.attributes.get('rowlines').split(' ') : [];
288
298
  var envName = node.attributes.get('name');
289
299
  /** Check if a table is enclosed in brackets */
290
- var isHasBranchOpen = node.parent && node.parent.kind === 'mrow' && ((_e = node.parent.properties) === null || _e === void 0 ? void 0 : _e.hasOwnProperty('open'));
291
- var isHasBranchClose = node.parent && node.parent.kind === 'mrow' && ((_f = node.parent.properties) === null || _f === void 0 ? void 0 : _f.hasOwnProperty('close'));
300
+ var isHasBranchOpen = node.parent && node.parent.kind === 'mrow' && ((_g = node.parent.properties) === null || _g === void 0 ? void 0 : _g.hasOwnProperty('open'));
301
+ var isHasBranchClose = node.parent && node.parent.kind === 'mrow' && ((_h = node.parent.properties) === null || _h === void 0 ? void 0 : _h.hasOwnProperty('close'));
292
302
  var thereAreBracketsIn_parent = (isHasBranchOpen && node.parent.properties['open'])
293
303
  || (isHasBranchClose && node.parent.properties['close']);
294
- var thereAreBracketsIn_Parent = parentIsMenclose && ((_g = node.Parent.Parent) === null || _g === void 0 ? void 0 : _g.isKind('mrow'))
295
- && ((((_h = node.Parent.Parent.properties) === null || _h === void 0 ? void 0 : _h.hasOwnProperty('open')) && node.Parent.Parent.properties['open'])
296
- || (((_j = node.Parent.Parent.properties) === null || _j === void 0 ? void 0 : _j.hasOwnProperty('close')) && node.Parent.Parent.properties['close']));
304
+ var thereAreBracketsIn_Parent = parentIsMenclose && ((_j = node.Parent.Parent) === null || _j === void 0 ? void 0 : _j.isKind('mrow'))
305
+ && ((((_k = node.Parent.Parent.properties) === null || _k === void 0 ? void 0 : _k.hasOwnProperty('open')) && node.Parent.Parent.properties['open'])
306
+ || (((_l = node.Parent.Parent.properties) === null || _l === void 0 ? void 0 : _l.hasOwnProperty('close')) && node.Parent.Parent.properties['close']));
297
307
  /** It is a matrix or system of equations with brackets */
298
308
  var isMatrixOrSystemOfEquations = thereAreBracketsIn_parent || thereAreBracketsIn_Parent;
299
309
  var itShouldBeFlatten = consts_1.envArraysShouldBeFlattenInTSV.includes(envName)
@@ -306,21 +316,25 @@ var mtable = function () {
306
316
  for (var i = 0; i < countRow; i++) {
307
317
  var mtrNode = node.childNodes[i];
308
318
  mtrNode.attributes.setInherited('toTsv', toTsv);
319
+ mtrNode.attributes.setInherited('toCsv', toCsv);
309
320
  mtrNode.attributes.setInherited('itShouldBeFlatten', itShouldBeFlatten);
310
321
  var mmlRow = '';
322
+ var mmlRow_tsv = '';
323
+ var mmlRow_csv = '';
311
324
  var mmlRowVerticalMath = '';
312
325
  var mathOperation = '';
313
- var countColl = (_k = mtrNode.childNodes) === null || _k === void 0 ? void 0 : _k.length;
326
+ var countColl = (_m = mtrNode.childNodes) === null || _m === void 0 ? void 0 : _m.length;
314
327
  /** It's EqnArray or AmsEqnArray or AlignAt.
315
328
  * eqnarray*, align, align*, split, gather, gather*, aligned, gathered, alignat, alignat*, alignedat */
316
329
  var isEqnArrayRow = mtrNode.attributes.get('displaystyle');
317
330
  for (var j = 0; j < countColl; j++) {
318
331
  if (j > 0 && !isEqnArrayRow) {
319
- mmlRow += toTsv ? ((_l = serialize.options.tsv_separators) === null || _l === void 0 ? void 0 : _l.column) || '\t'
320
- : itShouldBeFlatten ? ', ' : ',';
332
+ mmlRow += ',';
333
+ mmlRow_tsv += toTsv ? ((_o = serialize.options.tsv_separators) === null || _o === void 0 ? void 0 : _o.column) || '\t' : itShouldBeFlatten ? ', ' : ',';
334
+ mmlRow_csv += toCsv ? ((_p = serialize.options.csv_separators) === null || _p === void 0 ? void 0 : _p.column) || ',' : itShouldBeFlatten ? ', ' : ',';
321
335
  }
322
336
  var mtdNode = mtrNode.childNodes[j];
323
- var mmlColl = serialize.visitNode(mtdNode, '');
337
+ var _x = serialize.visitNode(mtdNode, ''), _y = _x.ascii, ascii = _y === void 0 ? '' : _y, _z = _x.ascii_tsv, ascii_tsv = _z === void 0 ? '' : _z, _0 = _x.ascii_csv, ascii_csv = _0 === void 0 ? '' : _0;
324
338
  var mmlCollVerticalMath = '';
325
339
  if (isVerticalMath) {
326
340
  var dataColl = getDataForVerticalMath(serialize, mtdNode, i);
@@ -333,30 +347,28 @@ var mtable = function () {
333
347
  isVerticalMath = false;
334
348
  }
335
349
  }
336
- mmlRow += !toTsv && itShouldBeFlatten ? mmlColl.trimEnd() : mmlColl;
350
+ mmlRow += ascii;
351
+ mmlRow_tsv += !toTsv && itShouldBeFlatten ? ascii_tsv.trimEnd() : ascii_tsv;
352
+ mmlRow_csv += !toCsv && itShouldBeFlatten ? ascii_csv.trimEnd() : ascii_csv;
337
353
  mmlRowVerticalMath += mmlCollVerticalMath;
338
354
  }
339
355
  /** For vertical math, if the horizontal line is in front of the answer, then replace it with an equals sign */
340
356
  if (isVerticalMath && (arrRowLines === null || arrRowLines === void 0 ? void 0 : arrRowLines.length) && (arrRowLines === null || arrRowLines === void 0 ? void 0 : arrRowLines.length) > i && arrRowLines[i] !== 'none') {
341
357
  mmlRowVerticalMath += '=';
342
358
  }
343
- if (toTsv || itShouldBeFlatten) {
344
- arrRows.push({
345
- mmlRow: mmlRow,
346
- mmlRowVerticalMath: mmlRowVerticalMath,
347
- mathOperation: mathOperation,
348
- encloseToSquareBrackets: false
349
- });
350
- continue;
351
- }
352
359
  /** It's EqnArray or AmsEqnArray or AlignAt.
353
360
  * eqnarray*, align, align*, split, gather, gather*, aligned, gathered, alignat, alignat*, alignedat */
354
- var isEqnArray = (_m = mtrNode.attributes) === null || _m === void 0 ? void 0 : _m.get('displaystyle');
361
+ var isEqnArray = (_q = mtrNode.attributes) === null || _q === void 0 ? void 0 : _q.get('displaystyle');
355
362
  arrRows.push({
356
363
  mmlRow: mmlRow,
364
+ mmlRow_tsv: mmlRow_tsv,
365
+ mmlRow_csv: mmlRow_csv,
357
366
  mmlRowVerticalMath: mmlRowVerticalMath,
358
367
  mathOperation: mathOperation,
359
- encloseToSquareBrackets: countRow > 1 || isSubExpression || (countColl > 1 && !isEqnArray)
368
+ encloseToSquareBrackets: countRow > 1 || isSubExpression || (countColl > 1 && !isEqnArray),
369
+ toTsv: toTsv,
370
+ toCsv: toCsv,
371
+ itShouldBeFlatten: itShouldBeFlatten
360
372
  });
361
373
  }
362
374
  /** If none of the row starts with math operation (+, -, times)
@@ -378,53 +390,93 @@ var mtable = function () {
378
390
  }
379
391
  }
380
392
  var mmlTableContent = '';
393
+ var mmlTableContent_tsv = '';
394
+ var mmlTableContent_csv = '';
381
395
  for (var i = 0; i < arrRows.length; i++) {
382
396
  if (i > 0 && !isVerticalMath) {
383
- mmlTableContent += toTsv
384
- ? ((_o = serialize.options.tsv_separators) === null || _o === void 0 ? void 0 : _o.row) || '\n'
397
+ mmlTableContent += ',';
398
+ mmlTableContent_tsv += toTsv
399
+ ? ((_r = serialize.options.tsv_separators) === null || _r === void 0 ? void 0 : _r.row) || '\n'
400
+ : itShouldBeFlatten ? ', ' : ',';
401
+ mmlTableContent_csv += toCsv
402
+ ? ((_s = serialize.options.csv_separators) === null || _s === void 0 ? void 0 : _s.row) || '\n'
385
403
  : itShouldBeFlatten ? ', ' : ',';
386
404
  }
387
- var mmlRow = isVerticalMath
388
- ? arrRows[i].mmlRowVerticalMath
389
- : arrRows[i].mmlRow;
405
+ var mmlRow = isVerticalMath ? arrRows[i].mmlRowVerticalMath : arrRows[i].mmlRow;
406
+ var mmlRow_tsv = isVerticalMath ? arrRows[i].mmlRowVerticalMath : arrRows[i].mmlRow_tsv;
407
+ var mmlRow_csv = isVerticalMath ? arrRows[i].mmlRowVerticalMath : arrRows[i].mmlRow_csv;
390
408
  mmlTableContent += arrRows[i].encloseToSquareBrackets && !isVerticalMath
391
409
  ? '[' + mmlRow + ']'
392
410
  : mmlRow;
411
+ mmlTableContent_tsv += arrRows[i].encloseToSquareBrackets
412
+ && !arrRows[i].itShouldBeFlatten && !arrRows[i].toTsv && !isVerticalMath
413
+ ? '[' + mmlRow_tsv + ']'
414
+ : mmlRow_tsv;
415
+ mmlTableContent_csv += arrRows[i].encloseToSquareBrackets
416
+ && !arrRows[i].itShouldBeFlatten && !arrRows[i].toCsv && !isVerticalMath
417
+ ? '[' + mmlRow_csv + ']'
418
+ : mmlRow_csv;
393
419
  }
394
420
  if (isVerticalMath) {
395
- if ((_p = node.Parent) === null || _p === void 0 ? void 0 : _p.isKind('mrow')) {
421
+ if ((_t = node.Parent) === null || _t === void 0 ? void 0 : _t.isKind('mrow')) {
396
422
  node.Parent.attributes.setInherited('isVerticalMath', true);
397
423
  }
398
- if (((_q = node.Parent) === null || _q === void 0 ? void 0 : _q.isKind('menclose')) && ((_s = (_r = node.Parent) === null || _r === void 0 ? void 0 : _r.Parent) === null || _s === void 0 ? void 0 : _s.isKind('mrow'))) {
424
+ if (((_u = node.Parent) === null || _u === void 0 ? void 0 : _u.isKind('menclose')) && ((_w = (_v = node.Parent) === null || _v === void 0 ? void 0 : _v.Parent) === null || _w === void 0 ? void 0 : _w.isKind('mrow'))) {
399
425
  node.Parent.Parent.attributes.setInherited('isVerticalMath', true);
400
426
  }
401
427
  }
402
428
  if (toTsv) {
403
- mml += '"';
404
- mml += mmlTableContent;
405
- mml += '"';
429
+ mml_tsv += '"' + mmlTableContent_tsv + '"';
406
430
  }
407
431
  else {
408
432
  if (itShouldBeFlatten || isVerticalMath) {
409
- mml += mmlTableContent;
433
+ mml_tsv += mmlTableContent_tsv;
410
434
  }
411
435
  else {
412
- mml += isHasBranchOpen || parentIsMenclose ? '' : '{:';
413
- mml += mmlTableContent;
414
- mml += isHasBranchClose || parentIsMenclose ? '' : ':}';
436
+ mml_tsv += isHasBranchOpen || parentIsMenclose ? '' : '{:';
437
+ mml_tsv += mmlTableContent_tsv;
438
+ mml_tsv += isHasBranchClose || parentIsMenclose ? '' : ':}';
415
439
  }
416
440
  }
417
- return mml;
441
+ if (toCsv) {
442
+ mml_csv += mmlTableContent_csv;
443
+ }
444
+ else {
445
+ if (itShouldBeFlatten || isVerticalMath) {
446
+ mml_csv += mmlTableContent_csv;
447
+ }
448
+ else {
449
+ mml_csv += isHasBranchOpen || parentIsMenclose ? '' : '{:';
450
+ mml_csv += mmlTableContent_csv;
451
+ mml_csv += isHasBranchClose || parentIsMenclose ? '' : ':}';
452
+ }
453
+ }
454
+ if (isVerticalMath) {
455
+ mml += mmlTableContent;
456
+ }
457
+ else {
458
+ mml += isHasBranchOpen || parentIsMenclose ? '' : '{:';
459
+ mml += mmlTableContent;
460
+ mml += isHasBranchClose || parentIsMenclose ? '' : ':}';
461
+ }
462
+ return {
463
+ ascii: mml,
464
+ ascii_tsv: mml_tsv,
465
+ ascii_csv: mml_csv,
466
+ };
418
467
  }
419
468
  catch (e) {
420
469
  console.error('mml => mtable =>', e);
421
- return mml;
470
+ return {
471
+ ascii: mml,
472
+ ascii_tsv: mml_tsv,
473
+ ascii_csv: mml_csv,
474
+ };
422
475
  }
423
476
  };
424
477
  };
425
478
  var mrow = function () {
426
479
  return function (node, serialize) {
427
- var mml = '';
428
480
  try {
429
481
  var isTexClass7 = node.properties && node.properties.texClass === MmlNode_1.TEXCLASS.INNER
430
482
  && node.parent && node.parent.kind === 'inferredMrow';
@@ -433,342 +485,541 @@ var mrow = function () {
433
485
  var needBranchClose = node.properties
434
486
  && node.properties.hasOwnProperty('close') && node.properties.close === '';
435
487
  var mmlContent = '';
488
+ var mmlContent_tsv = '';
489
+ var mmlContent_csv = '';
436
490
  for (var i = 0; i < node.childNodes.length; i++) {
437
- mmlContent += serialize.visitNode(node.childNodes[i], '');
491
+ var data = serialize.visitNode(node.childNodes[i], '');
492
+ mmlContent += data.ascii;
493
+ mmlContent_tsv += data.ascii_tsv;
494
+ mmlContent_csv += data.ascii_csv;
438
495
  }
439
496
  var isVerticalMath = node.attributes.get('isVerticalMath');
440
- mml += isTexClass7 && needBranchOpen && !isVerticalMath
441
- ? '{:'
442
- : '';
443
- mml += mmlContent;
444
- mml += isTexClass7 && needBranchClose && !isVerticalMath
445
- ? ':}' : '';
446
- return mml;
497
+ var open_1 = isTexClass7 && needBranchOpen && !isVerticalMath ? '{:' : '';
498
+ var close_1 = isTexClass7 && needBranchClose && !isVerticalMath ? ':}' : '';
499
+ return {
500
+ ascii: open_1 + mmlContent + close_1,
501
+ ascii_tsv: open_1 + mmlContent_tsv + close_1,
502
+ ascii_csv: open_1 + mmlContent_csv + close_1,
503
+ };
447
504
  }
448
505
  catch (e) {
449
506
  console.error('mml => mrow =>', e);
450
- return mml;
507
+ return {
508
+ ascii: '',
509
+ ascii_tsv: '',
510
+ ascii_csv: '',
511
+ };
451
512
  }
452
513
  };
453
514
  };
454
515
  var mtr = function () {
455
516
  return function (node, serialize) {
456
- var _a;
457
- var mml = '';
517
+ var _a, _b;
518
+ var res = {
519
+ ascii: '',
520
+ ascii_tsv: '',
521
+ ascii_csv: '',
522
+ };
458
523
  try {
459
524
  /** It's EqnArray or AmsEqnArray or AlignAt.
460
525
  * eqnarray*, align, align*, split, gather, gather*, aligned, gathered, alignat, alignat*, alignedat */
461
526
  var isEqnArray = node.attributes.get('displaystyle');
462
527
  var toTsv = node.attributes.get('toTsv');
528
+ var toCsv = node.attributes.get('toCsv');
463
529
  var itShouldBeFlatten = node.attributes.get('itShouldBeFlatten');
464
530
  for (var i = 0; i < node.childNodes.length; i++) {
465
531
  if (i > 0 && !isEqnArray) {
466
- mml += toTsv ? ((_a = serialize.options.tsv_separators) === null || _a === void 0 ? void 0 : _a.column) || '\t'
467
- : itShouldBeFlatten ? ', ' : ',';
532
+ res = common_1.AddToAsciiData(res, [
533
+ ',',
534
+ toTsv ? ((_a = serialize.options.tsv_separators) === null || _a === void 0 ? void 0 : _a.column) || '\t' : itShouldBeFlatten ? ', ' : ',',
535
+ toCsv ? ((_b = serialize.options.csv_separators) === null || _b === void 0 ? void 0 : _b.column) || ',' : itShouldBeFlatten ? ', ' : ','
536
+ ]);
468
537
  }
469
- var mmlCell = serialize.visitNode(node.childNodes[i], '');
470
- mml += !toTsv && itShouldBeFlatten ? mmlCell === null || mmlCell === void 0 ? void 0 : mmlCell.trimEnd() : mmlCell;
538
+ var _c = serialize.visitNode(node.childNodes[i], ''), _d = _c.ascii, ascii = _d === void 0 ? '' : _d, _e = _c.ascii_tsv, ascii_tsv = _e === void 0 ? '' : _e, _f = _c.ascii_csv, ascii_csv = _f === void 0 ? '' : _f;
539
+ res = common_1.AddToAsciiData(res, [
540
+ ascii,
541
+ !toTsv && itShouldBeFlatten ? ascii_tsv === null || ascii_tsv === void 0 ? void 0 : ascii_tsv.trimEnd() : ascii_tsv,
542
+ !toCsv && itShouldBeFlatten ? ascii_csv === null || ascii_csv === void 0 ? void 0 : ascii_csv.trimEnd() : ascii_csv
543
+ ]);
471
544
  }
472
- return mml;
545
+ return res;
473
546
  }
474
547
  catch (e) {
475
548
  console.error('mml => mtr =>', e);
476
- return mml;
549
+ return res;
477
550
  }
478
551
  };
479
552
  };
480
553
  var mpadded = function (handlerApi) {
481
554
  return function (node, serialize) {
482
- var mml = '';
555
+ var res = {
556
+ ascii: '',
557
+ ascii_tsv: '',
558
+ ascii_csv: ''
559
+ };
483
560
  try {
484
- var mmlAdd = handlerApi.handleAll(node, serialize, mml);
561
+ var mmlAdd = handlerApi.handleAll(node, serialize);
485
562
  if (node.Parent && node.Parent.kind === "menclose") {
486
563
  var atr = exports.getAttributes(node.Parent);
487
564
  if (atr && atr.notation === 'bottom' && atr.lcm) {
488
- if (!mmlAdd) {
489
- return '';
565
+ if (!mmlAdd || !mmlAdd.ascii) {
566
+ return res;
490
567
  }
491
568
  }
492
569
  }
493
- /** For tsv:
570
+ /** For tsv/csv:
494
571
  * Omit the " in nested arrays
495
572
  * */
496
- mml += serialize.options.tableToTsv ? '' : '"';
497
- mml += mmlAdd;
498
- mml += serialize.options.tableToTsv ? '' : '"';
499
- return mml;
573
+ res = common_1.AddToAsciiData(res, [
574
+ '"',
575
+ serialize.options.tableToTsv ? '' : '"',
576
+ ''
577
+ ]);
578
+ res = common_1.AddToAsciiData(res, [mmlAdd.ascii, mmlAdd.ascii_tsv, mmlAdd.ascii_csv]);
579
+ res = common_1.AddToAsciiData(res, [
580
+ '"',
581
+ serialize.options.tableToTsv ? '' : '"',
582
+ ''
583
+ ]);
584
+ return res;
500
585
  }
501
586
  catch (e) {
502
587
  console.error('mml => mpadded =>', e);
503
- return mml;
588
+ return res;
504
589
  }
505
590
  };
506
591
  };
507
592
  var mover = function (handlerApi) {
508
593
  return function (node, serialize) {
509
- var mml = '';
594
+ var res = {
595
+ ascii: '',
596
+ ascii_tsv: '',
597
+ ascii_csv: ''
598
+ };
510
599
  try {
511
600
  var firstChild = node.childNodes[0] ? node.childNodes[0] : '';
512
601
  var secondChild = node.childNodes[1] ? node.childNodes[1] : '';
602
+ var dataFirstChild = firstChild ? serialize.visitNode(firstChild, '') : null;
603
+ var dataSecondChild = secondChild ? serialize.visitNode(secondChild, '') : null;
513
604
  if (secondChild && secondChild.kind === 'mo') {
514
- var t = serialize.visitNode(secondChild, '');
605
+ var t = dataSecondChild.ascii;
515
606
  var asc = exports.FindSymbolToAM('mover', t, exports.getAttributes(secondChild));
516
607
  if (asc) {
517
- mml += ' ' + asc + '(';
518
- mml += serialize.visitNode(firstChild, '').trim();
519
- mml += ')';
608
+ res = common_1.AddToAsciiData(res, [' ' + asc + '(']);
609
+ res = common_1.AddToAsciiData(res, [
610
+ dataFirstChild ? dataFirstChild.ascii ? dataFirstChild.ascii.trim() : dataFirstChild.ascii : '',
611
+ dataFirstChild ? dataFirstChild.ascii_tsv ? dataFirstChild.ascii_tsv.trim() : dataFirstChild.ascii_tsv : '',
612
+ dataFirstChild ? dataFirstChild.ascii_csv ? dataFirstChild.ascii_csv.trim() : dataFirstChild.ascii_csv : '',
613
+ ]);
614
+ res = common_1.AddToAsciiData(res, [')']);
520
615
  }
521
616
  else {
522
- mml += serialize.visitNode(firstChild, '');
523
- mml += '^';
524
- mml += serialize.options.extraBrackets ? '(' : '';
525
- mml += serialize.visitNode(secondChild, '');
526
- mml += serialize.options.extraBrackets ? ')' : '';
617
+ res = common_1.AddToAsciiData(res, [
618
+ dataFirstChild ? dataFirstChild.ascii : '',
619
+ dataFirstChild ? dataFirstChild.ascii_tsv : '',
620
+ dataFirstChild ? dataFirstChild.ascii_csv : ''
621
+ ]);
622
+ res = common_1.AddToAsciiData(res, ['^']);
623
+ res = common_1.AddToAsciiData(res, [serialize.options.extraBrackets ? '(' : '']);
624
+ res = common_1.AddToAsciiData(res, [
625
+ dataSecondChild ? dataSecondChild.ascii : '',
626
+ dataSecondChild ? dataSecondChild.ascii_tsv : '',
627
+ dataSecondChild ? dataSecondChild.ascii_csv : ''
628
+ ]);
629
+ res = common_1.AddToAsciiData(res, [serialize.options.extraBrackets ? ')' : '']);
527
630
  }
528
631
  }
529
632
  else {
530
- mml += handlerApi.handleAll(node, serialize);
633
+ var data = handlerApi.handleAll(node, serialize);
634
+ res = common_1.AddToAsciiData(res, [data.ascii, data.ascii_tsv, data.ascii_csv]);
531
635
  }
532
- return mml;
636
+ return res;
533
637
  }
534
638
  catch (e) {
535
639
  console.error('mml => mover =>', e);
536
- return mml;
640
+ return res;
537
641
  }
538
642
  };
539
643
  };
540
644
  var munder = function (handlerApi) {
541
645
  return function (node, serialize) {
542
- var mml = '';
646
+ var res = {
647
+ ascii: '',
648
+ ascii_tsv: '',
649
+ ascii_csv: ''
650
+ };
543
651
  try {
544
652
  var firstChild = node.childNodes[0] ? node.childNodes[0] : null;
545
653
  var secondChild = node.childNodes[1] ? node.childNodes[1] : null;
654
+ var dataFirstChild = firstChild ? serialize.visitNode(firstChild, '') : null;
655
+ var dataSecondChild = secondChild ? serialize.visitNode(secondChild, '') : null;
546
656
  if (secondChild && secondChild.kind === 'mo') {
547
- var t = serialize.visitNode(secondChild, '');
657
+ var t = dataSecondChild.ascii;
548
658
  var asc = exports.FindSymbolToAM(node.kind, t);
549
659
  if (asc) {
550
- mml += asc + '(';
551
- mml += serialize.visitNode(firstChild, '');
552
- mml += ')';
660
+ res = common_1.AddToAsciiData(res, [asc + '(']);
661
+ res = common_1.AddToAsciiData(res, [
662
+ dataFirstChild ? dataFirstChild.ascii : '',
663
+ dataFirstChild ? dataFirstChild.ascii_tsv : '',
664
+ dataFirstChild ? dataFirstChild.ascii_csv : ''
665
+ ]);
666
+ res = common_1.AddToAsciiData(res, [asc + ')']);
553
667
  }
554
668
  else {
555
- mml += handlerApi.handleAll(node, serialize);
669
+ var data = handlerApi.handleAll(node, serialize);
670
+ res = common_1.AddToAsciiData(res, [data.ascii, data.ascii_tsv, data.ascii_csv]);
556
671
  }
557
672
  }
558
673
  else {
559
- mml += firstChild ? serialize.visitNode(firstChild, '') : '';
560
- mml += '_';
561
- mml += serialize.options.extraBrackets ? '(' : '';
562
- mml += secondChild ? serialize.visitNode(secondChild, '') : '';
563
- mml += serialize.options.extraBrackets ? ')' : '';
674
+ res = common_1.AddToAsciiData(res, [
675
+ dataFirstChild ? dataFirstChild.ascii : '',
676
+ dataFirstChild ? dataFirstChild.ascii_tsv : '',
677
+ dataFirstChild ? dataFirstChild.ascii_csv : ''
678
+ ]);
679
+ res = common_1.AddToAsciiData(res, ['_']);
680
+ res = common_1.AddToAsciiData(res, [serialize.options.extraBrackets ? '(' : '']);
681
+ res = common_1.AddToAsciiData(res, [
682
+ dataSecondChild ? dataSecondChild.ascii : '',
683
+ dataSecondChild ? dataSecondChild.ascii_tsv : '',
684
+ dataSecondChild ? dataSecondChild.ascii_csv : ''
685
+ ]);
686
+ res = common_1.AddToAsciiData(res, [serialize.options.extraBrackets ? ')' : '']);
564
687
  }
565
- return mml;
688
+ return res;
566
689
  }
567
690
  catch (e) {
568
691
  console.error('mml => munder =>', e);
569
- return mml;
692
+ return res;
570
693
  }
571
694
  };
572
695
  };
573
696
  var munderover = function () {
574
697
  return function (node, serialize) {
575
- var mml = '';
698
+ var res = {
699
+ ascii: '',
700
+ ascii_tsv: '',
701
+ ascii_csv: ''
702
+ };
576
703
  try {
577
704
  var firstChild = node.childNodes[0] ? node.childNodes[0] : null;
578
705
  var secondChild = node.childNodes[1] ? node.childNodes[1] : null;
579
706
  var thirdChild = node.childNodes[2] ? node.childNodes[2] : null;
580
- mml += firstChild ? serialize.visitNode(firstChild, '') : null;
581
- mml += '_';
582
- mml += serialize.options.extraBrackets ? '(' : '';
583
- mml += secondChild ? serialize.visitNode(secondChild, '') : null;
584
- mml += serialize.options.extraBrackets ? ')' : '';
585
- mml += '^';
586
- mml += serialize.options.extraBrackets ? '(' : '';
587
- mml += thirdChild ? serialize.visitNode(thirdChild, '') : null;
588
- mml += serialize.options.extraBrackets ? ')' : '';
589
- return mml;
707
+ var dataFirstChild = firstChild ? serialize.visitNode(firstChild, '') : null;
708
+ var dataSecondChild = secondChild ? serialize.visitNode(secondChild, '') : null;
709
+ var dataThirdChild = thirdChild ? serialize.visitNode(thirdChild, '') : null;
710
+ res = common_1.AddToAsciiData(res, [
711
+ dataFirstChild.ascii ? dataFirstChild.ascii : '',
712
+ dataFirstChild.ascii_tsv ? dataFirstChild.ascii_tsv : '',
713
+ dataFirstChild.ascii_csv ? dataFirstChild.ascii_csv : '',
714
+ ]);
715
+ res = common_1.AddToAsciiData(res, ['_']);
716
+ res = common_1.AddToAsciiData(res, [serialize.options.extraBrackets ? '(' : '']);
717
+ res = common_1.AddToAsciiData(res, [
718
+ dataSecondChild.ascii ? dataSecondChild.ascii : '',
719
+ dataSecondChild.ascii_tsv ? dataSecondChild.ascii_tsv : '',
720
+ dataSecondChild.ascii_csv ? dataSecondChild.ascii_csv : '',
721
+ ]);
722
+ res = common_1.AddToAsciiData(res, [serialize.options.extraBrackets ? ')' : '']);
723
+ res = common_1.AddToAsciiData(res, ['^']);
724
+ res = common_1.AddToAsciiData(res, [serialize.options.extraBrackets ? '(' : '']);
725
+ res = common_1.AddToAsciiData(res, [
726
+ dataThirdChild.ascii ? dataThirdChild.ascii : '',
727
+ dataThirdChild.ascii_tsv ? dataThirdChild.ascii_tsv : '',
728
+ dataThirdChild.ascii_csv ? dataThirdChild.ascii_csv : '',
729
+ ]);
730
+ res = common_1.AddToAsciiData(res, [serialize.options.extraBrackets ? ')' : '']);
731
+ return res;
590
732
  }
591
733
  catch (e) {
592
734
  console.error('mml => munderover =>', e);
593
- return mml;
735
+ return res;
594
736
  }
595
737
  };
596
738
  };
597
739
  var msub = function () {
598
740
  return function (node, serialize) {
599
- var mml = '';
741
+ var res = {
742
+ ascii: '',
743
+ ascii_tsv: '',
744
+ ascii_csv: ''
745
+ };
600
746
  try {
601
747
  var firstChild = node.childNodes[0] ? node.childNodes[0] : null;
602
748
  var secondChild = node.childNodes[1] ? node.childNodes[1] : null;
603
- mml += firstChild ? serialize.visitNode(firstChild, '') : '';
604
- mml += '_';
605
- mml += serialize.options.extraBrackets ? '(' : '';
606
- mml += secondChild ? serialize.visitNode(secondChild, '') : '';
607
- mml += serialize.options.extraBrackets ? ')' : '';
608
- return mml;
749
+ var dataFirstChild = firstChild ? serialize.visitNode(firstChild, '') : null;
750
+ var dataSecondChild = secondChild ? serialize.visitNode(secondChild, '') : null;
751
+ res = common_1.AddToAsciiData(res, [
752
+ dataFirstChild ? dataFirstChild.ascii : '',
753
+ dataFirstChild ? dataFirstChild.ascii_tsv : '',
754
+ dataFirstChild ? dataFirstChild.ascii_csv : ''
755
+ ]);
756
+ res = common_1.AddToAsciiData(res, ['_']);
757
+ res = common_1.AddToAsciiData(res, [serialize.options.extraBrackets ? '(' : '']);
758
+ res = common_1.AddToAsciiData(res, [
759
+ dataSecondChild ? dataSecondChild.ascii : '',
760
+ dataSecondChild ? dataSecondChild.ascii_tsv : '',
761
+ dataSecondChild ? dataSecondChild.ascii_csv : ''
762
+ ]);
763
+ res = common_1.AddToAsciiData(res, [serialize.options.extraBrackets ? ')' : '']);
764
+ return res;
609
765
  }
610
766
  catch (e) {
611
767
  console.error('mml => msub =>', e);
612
- return mml;
768
+ return res;
613
769
  }
614
770
  };
615
771
  };
616
772
  var msup = function () {
617
773
  return function (node, serialize) {
618
- var mml = '';
774
+ var res = {
775
+ ascii: '',
776
+ ascii_tsv: '',
777
+ ascii_csv: '',
778
+ };
619
779
  try {
620
780
  var firstChild = node.childNodes[0] ? node.childNodes[0] : null;
621
781
  var secondChild = node.childNodes[1] ? node.childNodes[1] : null;
622
- mml += firstChild ? serialize.visitNode(firstChild, '') : '';
623
- mml += '^';
624
- mml += serialize.options.extraBrackets ? '(' : '';
625
- mml += secondChild ? serialize.visitNode(secondChild, '') : '';
626
- mml += serialize.options.extraBrackets ? ')' : '';
627
- return mml;
782
+ var dataFirstChild = firstChild ? serialize.visitNode(firstChild, '') : null;
783
+ var dataSecondChild = secondChild ? serialize.visitNode(secondChild, '') : null;
784
+ res = common_1.AddToAsciiData(res, [
785
+ dataFirstChild ? dataFirstChild.ascii : '',
786
+ dataFirstChild ? dataFirstChild.ascii_tsv : '',
787
+ dataFirstChild ? dataFirstChild.ascii_csv : '',
788
+ ]);
789
+ res = common_1.AddToAsciiData(res, ['^']);
790
+ res = common_1.AddToAsciiData(res, [serialize.options.extraBrackets ? '(' : '']);
791
+ res = common_1.AddToAsciiData(res, [
792
+ dataSecondChild ? dataSecondChild.ascii : '',
793
+ dataSecondChild ? dataSecondChild.ascii_tsv : '',
794
+ dataSecondChild ? dataSecondChild.ascii_csv : '',
795
+ ]);
796
+ res = common_1.AddToAsciiData(res, [serialize.options.extraBrackets ? ')' : '']);
797
+ return res;
628
798
  }
629
799
  catch (e) {
630
800
  console.error('mml => msup =>', e);
631
- return mml;
801
+ return res;
632
802
  }
633
803
  };
634
804
  };
635
805
  var msubsup = function () {
636
806
  return function (node, serialize) {
637
- var mml = '';
807
+ var res = {
808
+ ascii: '',
809
+ ascii_tsv: '',
810
+ ascii_csv: ''
811
+ };
638
812
  try {
639
813
  var firstChild = node.childNodes[0] ? node.childNodes[0] : null;
640
814
  var secondChild = node.childNodes[1] ? node.childNodes[1] : null;
641
815
  var thirdChild = node.childNodes[2] ? node.childNodes[2] : null;
642
- mml += firstChild ? serialize.visitNode(firstChild, '') : '';
643
- mml += '_';
644
- mml += '(';
645
- mml += secondChild ? serialize.visitNode(secondChild, '') : '';
646
- mml += ')';
647
- mml += '^';
648
- mml += '(';
649
- mml += thirdChild ? serialize.visitNode(thirdChild, '') : '';
650
- mml += ')';
651
- return mml;
816
+ var dataFirstChild = firstChild ? serialize.visitNode(firstChild, '') : null;
817
+ var dataSecondChild = secondChild ? serialize.visitNode(secondChild, '') : null;
818
+ var dataThirdChild = thirdChild ? serialize.visitNode(thirdChild, '') : null;
819
+ res = common_1.AddToAsciiData(res, [
820
+ dataFirstChild ? dataFirstChild.ascii : '',
821
+ dataFirstChild ? dataFirstChild.ascii_tsv : '',
822
+ dataFirstChild ? dataFirstChild.ascii_csv : '',
823
+ ]);
824
+ res = common_1.AddToAsciiData(res, ['_']);
825
+ res = common_1.AddToAsciiData(res, ['(']);
826
+ res = common_1.AddToAsciiData(res, [
827
+ dataSecondChild ? dataSecondChild.ascii : '',
828
+ dataSecondChild ? dataSecondChild.ascii_tsv : '',
829
+ dataSecondChild ? dataSecondChild.ascii_csv : '',
830
+ ]);
831
+ res = common_1.AddToAsciiData(res, [')']);
832
+ res = common_1.AddToAsciiData(res, ['^']);
833
+ res = common_1.AddToAsciiData(res, ['(']);
834
+ res = common_1.AddToAsciiData(res, [
835
+ dataThirdChild ? dataThirdChild.ascii : '',
836
+ dataThirdChild ? dataThirdChild.ascii_tsv : '',
837
+ dataThirdChild ? dataThirdChild.ascii_csv : '',
838
+ ]);
839
+ res = common_1.AddToAsciiData(res, [')']);
840
+ return res;
652
841
  }
653
842
  catch (e) {
654
843
  console.error('mml => msubsup =>', e);
655
- return mml;
844
+ return res;
656
845
  }
657
846
  };
658
847
  };
659
- var msqrt = function (handlerApi) {
848
+ var msqrt = function () {
660
849
  return function (node, serialize) {
661
- var mml = '';
850
+ var res = {
851
+ ascii: '',
852
+ ascii_tsv: '',
853
+ ascii_csv: '',
854
+ };
662
855
  try {
663
856
  var firstChild = node.childNodes[0] ? node.childNodes[0] : null;
664
- mml += 'sqrt';
665
- mml += serialize.visitNode(firstChild, '');
666
- return mml;
857
+ var dataFirstChild = firstChild ? serialize.visitNode(firstChild, '') : null;
858
+ res = common_1.AddToAsciiData(res, ['sqrt']);
859
+ res = common_1.AddToAsciiData(res, [
860
+ dataFirstChild ? dataFirstChild.ascii : '',
861
+ dataFirstChild ? dataFirstChild.ascii_tsv : '',
862
+ dataFirstChild ? dataFirstChild.ascii_csv : ''
863
+ ]);
864
+ return res;
667
865
  }
668
866
  catch (e) {
669
867
  console.error('mml => msqrt =>', e);
670
- return mml;
868
+ return res;
671
869
  }
672
870
  };
673
871
  };
674
872
  var mroot = function () {
675
873
  return function (node, serialize) {
676
- var mml = '';
874
+ var res = {
875
+ ascii: '',
876
+ ascii_tsv: '',
877
+ ascii_csv: '',
878
+ };
677
879
  try {
678
880
  var firstChild = node.childNodes[0] ? node.childNodes[0] : null;
679
881
  var secondChild = node.childNodes[1] ? node.childNodes[1] : null;
680
- mml += 'root';
681
- mml += secondChild ? '(' + serialize.visitNode(secondChild, '') + ')' : '';
682
- mml += firstChild ? '(' + serialize.visitNode(firstChild, '') + ')' : '';
683
- return mml;
882
+ var dataSecondChild = secondChild ? serialize.visitNode(secondChild, '') : null;
883
+ var dataFirstChild = firstChild ? serialize.visitNode(firstChild, '') : null;
884
+ res = common_1.AddToAsciiData(res, ['root']);
885
+ res = common_1.AddToAsciiData(res, [secondChild ? '(' : '']);
886
+ res = common_1.AddToAsciiData(res, [
887
+ dataSecondChild ? dataSecondChild.ascii : '',
888
+ dataSecondChild ? dataSecondChild.ascii_tsv : '',
889
+ dataSecondChild ? dataSecondChild.ascii_csv : ''
890
+ ]);
891
+ res = common_1.AddToAsciiData(res, [secondChild ? ')' : '']);
892
+ res = common_1.AddToAsciiData(res, [firstChild ? '(' : '']);
893
+ res = common_1.AddToAsciiData(res, [
894
+ dataFirstChild ? dataFirstChild.ascii : '',
895
+ dataFirstChild ? dataFirstChild.ascii_tsv : '',
896
+ dataFirstChild ? dataFirstChild.ascii_csv : ''
897
+ ]);
898
+ res = common_1.AddToAsciiData(res, [firstChild ? ')' : '']);
899
+ return res;
684
900
  }
685
901
  catch (e) {
686
902
  console.error('mml => mroot =>', e);
687
- return mml;
903
+ return res;
688
904
  }
689
905
  };
690
906
  };
691
907
  var mfrac = function () {
692
908
  return function (node, serialize) {
693
- var mml = '';
909
+ var res = {
910
+ ascii: '',
911
+ ascii_tsv: '',
912
+ ascii_csv: '',
913
+ };
694
914
  try {
695
915
  var firstChild = node.childNodes[0] ? node.childNodes[0] : null;
696
916
  var secondChild = node.childNodes[1] ? node.childNodes[1] : null;
917
+ var dataFirstChild = firstChild ? serialize.visitNode(firstChild, '') : null;
918
+ var dataSecondChild = secondChild ? serialize.visitNode(secondChild, '') : null;
697
919
  if ((firstChild && firstChild.kind === "mrow" && firstChild.childNodes.length > 1) || serialize.options.extraBrackets) {
698
- mml += '(';
699
- mml += serialize.visitNode(firstChild, '');
700
- mml += ')';
920
+ res = common_1.AddToAsciiData(res, ['(']);
921
+ res = common_1.AddToAsciiData(res, [
922
+ dataFirstChild ? dataFirstChild.ascii : '',
923
+ dataFirstChild ? dataFirstChild.ascii_tsv : '',
924
+ dataFirstChild ? dataFirstChild.ascii_csv : '',
925
+ ]);
926
+ res = common_1.AddToAsciiData(res, [')']);
701
927
  }
702
928
  else {
703
- mml += serialize.visitNode(firstChild, '');
929
+ res = common_1.AddToAsciiData(res, [
930
+ dataFirstChild ? dataFirstChild.ascii : '',
931
+ dataFirstChild ? dataFirstChild.ascii_tsv : '',
932
+ dataFirstChild ? dataFirstChild.ascii_csv : '',
933
+ ]);
704
934
  }
705
- mml += '/';
935
+ res = common_1.AddToAsciiData(res, ['/']);
706
936
  if ((secondChild && secondChild.kind === "mrow" && secondChild.childNodes.length > 1) || serialize.options.extraBrackets) {
707
- mml += '(';
708
- mml += serialize.visitNode(secondChild, '');
709
- mml += ')';
937
+ res = common_1.AddToAsciiData(res, ['(']);
938
+ res = common_1.AddToAsciiData(res, [
939
+ dataSecondChild ? dataSecondChild.ascii : '',
940
+ dataSecondChild ? dataSecondChild.ascii_tsv : '',
941
+ dataSecondChild ? dataSecondChild.ascii_csv : '',
942
+ ]);
943
+ res = common_1.AddToAsciiData(res, [')']);
710
944
  }
711
945
  else {
712
- mml += serialize.visitNode(secondChild, '');
946
+ res = common_1.AddToAsciiData(res, [
947
+ dataSecondChild ? dataSecondChild.ascii : '',
948
+ dataSecondChild ? dataSecondChild.ascii_tsv : '',
949
+ dataSecondChild ? dataSecondChild.ascii_csv : '',
950
+ ]);
713
951
  }
714
- return mml;
952
+ return res;
715
953
  }
716
954
  catch (e) {
717
955
  console.error('mml => mfrac =>', e);
718
- return mml;
956
+ return res;
719
957
  }
720
958
  };
721
959
  };
722
960
  var mtext = function () {
723
961
  return function (node, serialize) {
724
- var mml = '';
962
+ var res = {
963
+ ascii: '',
964
+ ascii_tsv: '',
965
+ ascii_csv: ''
966
+ };
725
967
  try {
726
968
  if (!node.childNodes || node.childNodes.length === 0) {
727
- return mml;
969
+ return res;
728
970
  }
729
971
  var firstChild = node.childNodes[0];
730
972
  var value = exports.FindSymbolReplace(firstChild.text);
731
973
  var asc = exports.FindSymbolToAM(node.kind, value);
732
974
  if (asc) {
733
- mml += asc;
734
- return mml;
975
+ res = common_1.AddToAsciiData(res, [asc]);
976
+ return res;
735
977
  }
736
978
  var toTsv = node.attributes.get('toTsv');
737
- if (value[0] === '(' || toTsv) {
738
- if (toTsv) {
739
- value = value.replace(/"/g, '');
740
- }
741
- mml += value;
979
+ var toCsv = node.attributes.get('toCsv');
980
+ if (value[0] === '(' || toTsv || toCsv) {
981
+ res = common_1.AddToAsciiData(res, [
982
+ value[0] === '(' ? value.replace(/"/g, '') : value,
983
+ toTsv ? value.replace(/"/g, '') : value,
984
+ toCsv ? value.replace(/"/g, '') : value,
985
+ ]);
742
986
  }
743
987
  else {
744
988
  if (!value || (value && !value.trim())) {
745
- mml += '';
989
+ res = common_1.AddToAsciiData(res, ['']);
746
990
  }
747
991
  else {
748
- /** For tsv:
992
+ /** For tsv/csv:
749
993
  * Omit the " in nested arrays */
750
- if (serialize.options.tableToTsv) {
751
- mml += value.replace(/"/g, '');
752
- }
753
- else {
754
- mml += '"' + value + '"';
755
- }
994
+ res = common_1.AddToAsciiData(res, [
995
+ '"' + value + '"',
996
+ serialize.options.tableToTsv
997
+ ? value.replace(/"/g, '')
998
+ : '"' + value + '"',
999
+ serialize.options.tableToCsv
1000
+ ? value.replace(/"/g, '')
1001
+ : value
1002
+ ]);
756
1003
  }
757
1004
  }
758
- return mml;
1005
+ return res;
759
1006
  }
760
1007
  catch (e) {
761
1008
  console.error('mml => mtext =>', e);
762
- return mml;
1009
+ return res;
763
1010
  }
764
1011
  };
765
1012
  };
766
1013
  var mi = function () {
767
1014
  return function (node, serialize) {
768
- var mml = '';
1015
+ var res = {
1016
+ ascii: '',
1017
+ ascii_tsv: '',
1018
+ ascii_csv: ''
1019
+ };
769
1020
  try {
770
1021
  if (!node.childNodes || node.childNodes.length === 0) {
771
- return mml;
1022
+ return res;
772
1023
  }
773
1024
  var firstChild = node.childNodes[0];
774
1025
  var value = firstChild.text;
@@ -777,86 +1028,105 @@ var mi = function () {
777
1028
  : null;
778
1029
  var abs = exports.SymbolToAM(node.kind, value, atr);
779
1030
  if (abs && abs.length > 1 && regW.test(abs[0])) {
780
- mml += needFirstSpase(node) ? ' ' : '';
781
- mml += abs;
782
- mml += needLastSpase(node) ? ' ' : '';
1031
+ res = common_1.AddToAsciiData(res, [needFirstSpace(node) ? ' ' : '']);
1032
+ res = common_1.AddToAsciiData(res, [abs]);
1033
+ res = common_1.AddToAsciiData(res, [needLastSpace(node) ? ' ' : '']);
783
1034
  }
784
1035
  else {
785
- mml += abs;
1036
+ res = common_1.AddToAsciiData(res, [abs]);
786
1037
  }
787
- return mml;
1038
+ return res;
788
1039
  }
789
1040
  catch (e) {
790
1041
  console.error('mml => mi =>', e);
791
- return mml;
1042
+ return res;
792
1043
  }
793
1044
  };
794
1045
  };
795
1046
  var mo = function () {
796
1047
  return function (node, serialize) {
797
- var mml = '';
1048
+ var res = {
1049
+ ascii: '',
1050
+ ascii_tsv: '',
1051
+ ascii_csv: ''
1052
+ };
798
1053
  try {
799
- var value = getChilrenText(node);
1054
+ var value = getChildrenText(node);
800
1055
  if (value === '\u2061') {
801
- return mml;
1056
+ return res;
802
1057
  }
803
1058
  var atr = exports.getAttributes(node);
804
1059
  var abs = exports.SymbolToAM(node.kind, value, atr, serialize.options.showStyle);
805
1060
  if (abs && abs.length > 1) {
806
- mml += regW.test(abs[0]) && needFirstSpase(node) ? ' ' : '';
807
- mml += abs;
808
- mml += regW.test(abs[abs.length - 1]) && needLastSpase(node) ? ' ' : '';
1061
+ res = common_1.AddToAsciiData(res, [regW.test(abs[0]) && needFirstSpace(node) ? ' ' : '']);
1062
+ res = common_1.AddToAsciiData(res, [abs]);
1063
+ res = common_1.AddToAsciiData(res, [regW.test(abs[abs.length - 1]) && needLastSpace(node) ? ' ' : '']);
809
1064
  }
810
1065
  else {
811
1066
  if (abs === ',' && node.Parent.kind === 'mtd') {
812
- /** For tsv:
1067
+ /** For tsv/csv:
813
1068
  * Omit the " in nested arrays */
814
- mml += serialize.options.tableToTsv ? '' : '"';
815
- mml += abs;
816
- mml += serialize.options.tableToTsv ? '' : '"';
1069
+ res = common_1.AddToAsciiData(res, [
1070
+ '"' + abs + '"',
1071
+ "" + (serialize.options.tableToTsv ? abs : '"' + abs + '"'),
1072
+ abs,
1073
+ ]);
817
1074
  }
818
1075
  else {
819
- mml += abs === '"' && serialize.options.tableToTsv ? '' : abs;
1076
+ res = common_1.AddToAsciiData(res, [
1077
+ abs,
1078
+ abs === '"' ? '' : abs,
1079
+ abs === '"' ? '' : abs,
1080
+ ]);
820
1081
  }
821
1082
  }
822
1083
  if (node.Parent && node.Parent.kind === "mpadded" && node.Parent.Parent && node.Parent.Parent.kind === "menclose") {
823
1084
  var atr_1 = exports.getAttributes(node.Parent.Parent);
824
1085
  if (atr_1.notation && atr_1.notation.toString().indexOf("bottom") !== -1) {
825
1086
  node.Parent.Parent.attributes.attributes.lcm = true;
826
- return '';
1087
+ return {
1088
+ ascii: '',
1089
+ ascii_tsv: '',
1090
+ ascii_csv: '',
1091
+ };
827
1092
  }
828
1093
  }
829
- return mml;
1094
+ return res;
830
1095
  }
831
1096
  catch (e) {
832
1097
  console.error('mml => mo =>', e);
833
- return mml;
1098
+ return res;
834
1099
  }
835
1100
  };
836
1101
  };
837
1102
  var mspace = function (handlerApi) {
838
1103
  return function (node, serialize) {
839
- var mml = '';
1104
+ var res = {
1105
+ ascii: '',
1106
+ ascii_tsv: '',
1107
+ ascii_csv: '',
1108
+ };
840
1109
  try {
841
1110
  var atr = exports.getAttributes(node);
842
1111
  if (atr && atr.width === "2em") {
843
- mml += node.parent.parent && needFirstSpase(node.parent.parent) ? ' ' : '';
844
- mml += 'qquad';
845
- mml += node.parent.parent && needLastSpase(node.parent.parent) ? ' ' : '';
846
- return mml;
1112
+ res = common_1.AddToAsciiData(res, [node.parent.parent && needFirstSpace(node.parent.parent) ? ' ' : '']);
1113
+ res = common_1.AddToAsciiData(res, ['qquad']);
1114
+ res = common_1.AddToAsciiData(res, [node.parent.parent && needLastSpace(node.parent.parent) ? ' ' : '']);
1115
+ return res;
847
1116
  }
848
1117
  if (atr && atr.width === "1em") {
849
- mml += node.parent.parent && needFirstSpase(node.parent.parent) ? ' ' : '';
850
- mml += 'quad';
851
- mml += node.parent.parent && needLastSpase(node.parent.parent) ? ' ' : '';
852
- return mml;
1118
+ res = common_1.AddToAsciiData(res, [node.parent.parent && needFirstSpace(node.parent.parent) ? ' ' : '']);
1119
+ res = common_1.AddToAsciiData(res, ['quad']);
1120
+ res = common_1.AddToAsciiData(res, [node.parent.parent && needLastSpace(node.parent.parent) ? ' ' : '']);
1121
+ return res;
853
1122
  }
854
- mml += handlerApi.handleAll(node, serialize, mml);
855
- return mml;
1123
+ var data = handlerApi.handleAll(node, serialize);
1124
+ res = common_1.AddToAsciiData(res, [data.ascii, data.ascii_tsv, data.ascii_csv]);
1125
+ return res;
856
1126
  }
857
1127
  catch (e) {
858
1128
  console.error('mml => mspace =>', e);
859
- return mml;
1129
+ return res;
860
1130
  }
861
1131
  };
862
1132
  };
@@ -864,23 +1134,34 @@ exports.handle = function (node, serialize) {
864
1134
  var handler = handlers[node.kind] || defHandle;
865
1135
  return handler(node, serialize);
866
1136
  };
867
- var handleAll = function (node, serialize, mml) {
1137
+ var handleAll = function (node, serialize) {
868
1138
  var e_2, _a;
869
- if (mml === void 0) { mml = ''; }
1139
+ var res = {
1140
+ ascii: '',
1141
+ ascii_tsv: '',
1142
+ ascii_csv: '',
1143
+ };
870
1144
  try {
871
- for (var _b = tslib_1.__values(node.childNodes), _c = _b.next(); !_c.done; _c = _b.next()) {
872
- var child = _c.value;
873
- mml += serialize.visitNode(child, '');
874
- }
875
- }
876
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
877
- finally {
878
1145
  try {
879
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1146
+ for (var _b = tslib_1.__values(node.childNodes), _c = _b.next(); !_c.done; _c = _b.next()) {
1147
+ var child = _c.value;
1148
+ var data = serialize.visitNode(child, '');
1149
+ res = common_1.AddToAsciiData(res, [data.ascii, data.ascii_tsv, data.ascii_csv]);
1150
+ }
1151
+ }
1152
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1153
+ finally {
1154
+ try {
1155
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1156
+ }
1157
+ finally { if (e_2) throw e_2.error; }
880
1158
  }
881
- finally { if (e_2) throw e_2.error; }
1159
+ return res;
1160
+ }
1161
+ catch (e) {
1162
+ console.error('mml => handleAll =>', e);
1163
+ return res;
882
1164
  }
883
- return mml;
884
1165
  };
885
1166
  var handlerApi = {
886
1167
  handle: exports.handle,
@@ -894,7 +1175,7 @@ var handlers = {
894
1175
  msup: msup(),
895
1176
  msub: msub(),
896
1177
  msubsup: msubsup(),
897
- msqrt: msqrt(handlerApi),
1178
+ msqrt: msqrt(),
898
1179
  mover: mover(handlerApi),
899
1180
  munder: munder(handlerApi),
900
1181
  munderover: munderover(),