case_limit.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import * as DomUtil from '../common/dom_util.js';
  2. import { SemanticType } from '../semantic_tree/semantic_meaning.js';
  3. import { MMLTAGS } from '../semantic_tree/semantic_util.js';
  4. import { AbstractEnrichCase } from './abstract_enrich_case.js';
  5. import * as EnrichMathml from './enrich_mathml.js';
  6. import { setAttributes } from './enrich_attr.js';
  7. export class CaseLimit extends AbstractEnrichCase {
  8. static test(semantic) {
  9. if (!semantic.mathmlTree || !semantic.childNodes.length) {
  10. return false;
  11. }
  12. const mmlTag = DomUtil.tagName(semantic.mathmlTree);
  13. const type = semantic.type;
  14. return (((type === SemanticType.LIMUPPER || type === SemanticType.LIMLOWER) &&
  15. (mmlTag === MMLTAGS.MSUBSUP || mmlTag === MMLTAGS.MUNDEROVER)) ||
  16. (type === SemanticType.LIMBOTH &&
  17. (mmlTag === MMLTAGS.MSUB ||
  18. mmlTag === MMLTAGS.MUNDER ||
  19. mmlTag === MMLTAGS.MSUP ||
  20. mmlTag === MMLTAGS.MOVER)));
  21. }
  22. static walkTree_(node) {
  23. if (node) {
  24. EnrichMathml.walkTree(node);
  25. }
  26. }
  27. constructor(semantic) {
  28. super(semantic);
  29. this.mml = semantic.mathmlTree;
  30. }
  31. getMathml() {
  32. const children = this.semantic.childNodes;
  33. if (this.semantic.type !== SemanticType.LIMBOTH &&
  34. this.mml.childNodes.length >= 3) {
  35. this.mml = EnrichMathml.introduceNewLayer([this.mml], this.semantic);
  36. }
  37. setAttributes(this.mml, this.semantic);
  38. if (!children[0].mathmlTree) {
  39. children[0].mathmlTree = this.semantic.mathmlTree;
  40. }
  41. children.forEach(CaseLimit.walkTree_);
  42. return this.mml;
  43. }
  44. }