enrich.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.semanticMathmlNode = semanticMathmlNode;
  4. exports.semanticMathmlSync = semanticMathmlSync;
  5. exports.semanticMathml = semanticMathml;
  6. exports.testTranslation = testTranslation;
  7. exports.prepareMmlString = prepareMmlString;
  8. const debugger_js_1 = require("../common/debugger.js");
  9. const DomUtil = require("../common/dom_util.js");
  10. const engine_js_1 = require("../common/engine.js");
  11. const Semantic = require("../semantic_tree/semantic.js");
  12. const EnrichMathml = require("./enrich_mathml.js");
  13. require("./enrich_case_factory.js");
  14. function semanticMathmlNode(mml) {
  15. const clone = DomUtil.cloneNode(mml);
  16. const tree = Semantic.getTree(clone);
  17. return EnrichMathml.enrich(clone, tree);
  18. }
  19. function semanticMathmlSync(expr) {
  20. const mml = DomUtil.parseInput(expr);
  21. return semanticMathmlNode(mml);
  22. }
  23. function semanticMathml(expr, callback) {
  24. engine_js_1.EnginePromise.getall().then(() => {
  25. const mml = DomUtil.parseInput(expr);
  26. callback(semanticMathmlNode(mml));
  27. });
  28. }
  29. function testTranslation(expr) {
  30. debugger_js_1.Debugger.getInstance().init();
  31. const mml = semanticMathmlSync(prepareMmlString(expr));
  32. debugger_js_1.Debugger.getInstance().exit();
  33. return mml;
  34. }
  35. function prepareMmlString(expr) {
  36. if (!expr.match(/^<math/)) {
  37. expr = '<math>' + expr;
  38. }
  39. if (!expr.match(/\/math>$/)) {
  40. expr += '</math>';
  41. }
  42. return expr;
  43. }