case_binomial.js 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. import * as DomUtil from '../common/dom_util.js';
  2. import { SemanticRole, SemanticType } from '../semantic_tree/semantic_meaning.js';
  3. import { AbstractEnrichCase } from './abstract_enrich_case.js';
  4. import { walkTree } from './enrich_mathml.js';
  5. import { addMrow, setAttributes, Attribute } from './enrich_attr.js';
  6. export class CaseBinomial extends AbstractEnrichCase {
  7. static test(semantic) {
  8. return (!semantic.mathmlTree &&
  9. semantic.type === SemanticType.LINE &&
  10. semantic.role === SemanticRole.BINOMIAL);
  11. }
  12. constructor(semantic) {
  13. super(semantic);
  14. this.mml = semantic.mathmlTree;
  15. }
  16. getMathml() {
  17. if (!this.semantic.childNodes.length) {
  18. return this.mml;
  19. }
  20. const child = this.semantic.childNodes[0];
  21. this.mml = walkTree(child);
  22. if (this.mml.hasAttribute(Attribute.TYPE)) {
  23. const mrow = addMrow();
  24. DomUtil.replaceNode(this.mml, mrow);
  25. mrow.appendChild(this.mml);
  26. this.mml = mrow;
  27. }
  28. setAttributes(this.mml, this.semantic);
  29. return this.mml;
  30. }
  31. }