enrich.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { Debugger } from '../common/debugger.js';
  2. import * as DomUtil from '../common/dom_util.js';
  3. import { EnginePromise } from '../common/engine.js';
  4. import * as Semantic from '../semantic_tree/semantic.js';
  5. import * as EnrichMathml from './enrich_mathml.js';
  6. import './enrich_case_factory.js';
  7. export function semanticMathmlNode(mml) {
  8. const clone = DomUtil.cloneNode(mml);
  9. const tree = Semantic.getTree(clone);
  10. return EnrichMathml.enrich(clone, tree);
  11. }
  12. export function semanticMathmlSync(expr) {
  13. const mml = DomUtil.parseInput(expr);
  14. return semanticMathmlNode(mml);
  15. }
  16. export function semanticMathml(expr, callback) {
  17. EnginePromise.getall().then(() => {
  18. const mml = DomUtil.parseInput(expr);
  19. callback(semanticMathmlNode(mml));
  20. });
  21. }
  22. export function testTranslation(expr) {
  23. Debugger.getInstance().init();
  24. const mml = semanticMathmlSync(prepareMmlString(expr));
  25. Debugger.getInstance().exit();
  26. return mml;
  27. }
  28. export function prepareMmlString(expr) {
  29. if (!expr.match(/^<math/)) {
  30. expr = '<math>' + expr;
  31. }
  32. if (!expr.match(/\/math>$/)) {
  33. expr += '</math>';
  34. }
  35. return expr;
  36. }