case_text.js 1.0 KB

123456789101112131415161718192021222324
  1. import { SemanticRole, SemanticType } from '../semantic_tree/semantic_meaning.js';
  2. import { AbstractEnrichCase } from './abstract_enrich_case.js';
  3. import * as EnrichMathml from './enrich_mathml.js';
  4. import { setAttributes, Attribute } from './enrich_attr.js';
  5. export class CaseText extends AbstractEnrichCase {
  6. static test(semantic) {
  7. return (semantic.type === SemanticType.PUNCTUATED &&
  8. (semantic.role === SemanticRole.TEXT ||
  9. semantic.contentNodes.every((x) => x.role === SemanticRole.DUMMY)));
  10. }
  11. constructor(semantic) {
  12. super(semantic);
  13. this.mml = semantic.mathmlTree;
  14. }
  15. getMathml() {
  16. const children = [];
  17. const collapsed = EnrichMathml.collapsePunctuated(this.semantic, children);
  18. this.mml = EnrichMathml.introduceNewLayer(children, this.semantic);
  19. setAttributes(this.mml, this.semantic);
  20. this.mml.removeAttribute(Attribute.CONTENT);
  21. EnrichMathml.addCollapsedAttribute(this.mml, collapsed);
  22. return this.mml;
  23. }
  24. }