case_empheq.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.CaseEmpheq = void 0;
  4. const semantic_util_js_1 = require("../semantic_tree/semantic_util.js");
  5. const abstract_enrich_case_js_1 = require("./abstract_enrich_case.js");
  6. const EnrichMathml = require("./enrich_mathml.js");
  7. const enrich_attr_js_1 = require("./enrich_attr.js");
  8. const DomUtil = require("../common/dom_util.js");
  9. class CaseEmpheq extends abstract_enrich_case_js_1.AbstractEnrichCase {
  10. static test(semantic) {
  11. return !!semantic.mathmlTree && semantic.hasAnnotation('Emph', 'top');
  12. }
  13. constructor(semantic) {
  14. super(semantic);
  15. this.mrows = [];
  16. this.mml = semantic.mathmlTree;
  17. }
  18. getMathml() {
  19. this.recurseToTable(this.semantic);
  20. if (this.mrows.length) {
  21. const newRow = (0, enrich_attr_js_1.addMrow)();
  22. const parent = this.mml.parentNode;
  23. parent.insertBefore(newRow, this.mml);
  24. for (const mrow of this.mrows) {
  25. newRow.appendChild(mrow);
  26. }
  27. newRow.appendChild(this.mml);
  28. }
  29. return this.mml;
  30. }
  31. recurseToTable(node) {
  32. var _a, _b;
  33. if (!(node.hasAnnotation('Emph', 'top') || node.hasAnnotation('Emph', 'fence')) &&
  34. (node.hasAnnotation('Emph', 'left') ||
  35. node.hasAnnotation('Emph', 'right'))) {
  36. EnrichMathml.walkTree(node);
  37. return;
  38. }
  39. if (!node.mathmlTree ||
  40. (DomUtil.tagName(node.mathmlTree) === semantic_util_js_1.MMLTAGS.MTABLE &&
  41. ((_a = node.annotation['Emph']) === null || _a === void 0 ? void 0 : _a.length) &&
  42. node.annotation['Emph'][0] !== 'table')) {
  43. const newNode = (0, enrich_attr_js_1.addMrow)();
  44. (0, enrich_attr_js_1.setAttributes)(newNode, node);
  45. this.mrows.unshift(newNode);
  46. }
  47. else {
  48. if (DomUtil.tagName(node.mathmlTree) === semantic_util_js_1.MMLTAGS.MTABLE &&
  49. ((_b = node.annotation['Emph']) === null || _b === void 0 ? void 0 : _b.length) &&
  50. node.annotation['Emph'][0] === 'table') {
  51. this.finalizeTable(node);
  52. return;
  53. }
  54. (0, enrich_attr_js_1.setAttributes)(node.mathmlTree, node);
  55. }
  56. node.childNodes.forEach(this.recurseToTable.bind(this));
  57. if (node.textContent || node.type === 'punctuated') {
  58. const newContent = node.contentNodes.map((x) => {
  59. const newNode = EnrichMathml.cloneContentNode(x);
  60. if (newNode.hasAttribute('data-semantic-added')) {
  61. this.mrows.unshift(newNode);
  62. }
  63. else {
  64. this.recurseToTable(x);
  65. }
  66. return newNode;
  67. });
  68. EnrichMathml.setOperatorAttribute(node, newContent);
  69. return;
  70. }
  71. node.contentNodes.forEach(this.recurseToTable.bind(this));
  72. }
  73. finalizeTable(node) {
  74. (0, enrich_attr_js_1.setAttributes)(node.mathmlTree, node);
  75. node.contentNodes.forEach((x) => {
  76. EnrichMathml.walkTree(x);
  77. });
  78. node.childNodes.forEach((x) => {
  79. EnrichMathml.walkTree(x);
  80. });
  81. }
  82. }
  83. exports.CaseEmpheq = CaseEmpheq;