case_binomial.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.CaseBinomial = void 0;
  4. const DomUtil = require("../common/dom_util.js");
  5. const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
  6. const abstract_enrich_case_js_1 = require("./abstract_enrich_case.js");
  7. const enrich_mathml_js_1 = require("./enrich_mathml.js");
  8. const enrich_attr_js_1 = require("./enrich_attr.js");
  9. class CaseBinomial extends abstract_enrich_case_js_1.AbstractEnrichCase {
  10. static test(semantic) {
  11. return (!semantic.mathmlTree &&
  12. semantic.type === semantic_meaning_js_1.SemanticType.LINE &&
  13. semantic.role === semantic_meaning_js_1.SemanticRole.BINOMIAL);
  14. }
  15. constructor(semantic) {
  16. super(semantic);
  17. this.mml = semantic.mathmlTree;
  18. }
  19. getMathml() {
  20. if (!this.semantic.childNodes.length) {
  21. return this.mml;
  22. }
  23. const child = this.semantic.childNodes[0];
  24. this.mml = (0, enrich_mathml_js_1.walkTree)(child);
  25. if (this.mml.hasAttribute(enrich_attr_js_1.Attribute.TYPE)) {
  26. const mrow = (0, enrich_attr_js_1.addMrow)();
  27. DomUtil.replaceNode(this.mml, mrow);
  28. mrow.appendChild(this.mml);
  29. this.mml = mrow;
  30. }
  31. (0, enrich_attr_js_1.setAttributes)(this.mml, this.semantic);
  32. return this.mml;
  33. }
  34. }
  35. exports.CaseBinomial = CaseBinomial;