case_limit.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.CaseLimit = 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 CaseLimit extends abstract_enrich_case_js_1.AbstractEnrichCase {
  11. static test(semantic) {
  12. if (!semantic.mathmlTree || !semantic.childNodes.length) {
  13. return false;
  14. }
  15. const mmlTag = DomUtil.tagName(semantic.mathmlTree);
  16. const type = semantic.type;
  17. return (((type === semantic_meaning_js_1.SemanticType.LIMUPPER || type === semantic_meaning_js_1.SemanticType.LIMLOWER) &&
  18. (mmlTag === semantic_util_js_1.MMLTAGS.MSUBSUP || mmlTag === semantic_util_js_1.MMLTAGS.MUNDEROVER)) ||
  19. (type === semantic_meaning_js_1.SemanticType.LIMBOTH &&
  20. (mmlTag === semantic_util_js_1.MMLTAGS.MSUB ||
  21. mmlTag === semantic_util_js_1.MMLTAGS.MUNDER ||
  22. mmlTag === semantic_util_js_1.MMLTAGS.MSUP ||
  23. mmlTag === semantic_util_js_1.MMLTAGS.MOVER)));
  24. }
  25. static walkTree_(node) {
  26. if (node) {
  27. EnrichMathml.walkTree(node);
  28. }
  29. }
  30. constructor(semantic) {
  31. super(semantic);
  32. this.mml = semantic.mathmlTree;
  33. }
  34. getMathml() {
  35. const children = this.semantic.childNodes;
  36. if (this.semantic.type !== semantic_meaning_js_1.SemanticType.LIMBOTH &&
  37. this.mml.childNodes.length >= 3) {
  38. this.mml = EnrichMathml.introduceNewLayer([this.mml], this.semantic);
  39. }
  40. (0, enrich_attr_js_1.setAttributes)(this.mml, this.semantic);
  41. if (!children[0].mathmlTree) {
  42. children[0].mathmlTree = this.semantic.mathmlTree;
  43. }
  44. children.forEach(CaseLimit.walkTree_);
  45. return this.mml;
  46. }
  47. }
  48. exports.CaseLimit = CaseLimit;