case_table.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.CaseTable = void 0;
  4. const DomUtil = require("../common/dom_util.js");
  5. const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
  6. const semantic_util_js_1 = require("../semantic_tree/semantic_util.js");
  7. const abstract_enrich_case_js_1 = require("./abstract_enrich_case.js");
  8. const EnrichMathml = require("./enrich_mathml.js");
  9. const enrich_attr_js_1 = require("./enrich_attr.js");
  10. class CaseTable extends abstract_enrich_case_js_1.AbstractEnrichCase {
  11. static test(semantic) {
  12. return (semantic.type === semantic_meaning_js_1.SemanticType.MATRIX ||
  13. semantic.type === semantic_meaning_js_1.SemanticType.VECTOR ||
  14. semantic.type === semantic_meaning_js_1.SemanticType.CASES);
  15. }
  16. constructor(semantic) {
  17. super(semantic);
  18. this.inner = [];
  19. this.mml = semantic.mathmlTree;
  20. }
  21. getMathml() {
  22. const lfence = EnrichMathml.cloneContentNode(this.semantic.contentNodes[0]);
  23. const rfence = this.semantic.contentNodes[1]
  24. ? EnrichMathml.cloneContentNode(this.semantic.contentNodes[1])
  25. : null;
  26. this.inner = this.semantic.childNodes.map(EnrichMathml.walkTree);
  27. if (!this.mml) {
  28. this.mml = EnrichMathml.introduceNewLayer([lfence].concat(this.inner, [rfence]), this.semantic);
  29. }
  30. else if (DomUtil.tagName(this.mml) === semantic_util_js_1.MMLTAGS.MFENCED) {
  31. const children = this.mml.childNodes;
  32. this.mml.insertBefore(lfence, children[0] || null);
  33. if (rfence) {
  34. this.mml.appendChild(rfence);
  35. }
  36. this.mml = EnrichMathml.rewriteMfenced(this.mml);
  37. }
  38. else {
  39. const newChildren = [lfence, this.mml];
  40. if (rfence) {
  41. newChildren.push(rfence);
  42. }
  43. this.mml = EnrichMathml.introduceNewLayer(newChildren, this.semantic);
  44. }
  45. (0, enrich_attr_js_1.setAttributes)(this.mml, this.semantic);
  46. return this.mml;
  47. }
  48. }
  49. exports.CaseTable = CaseTable;