MmlVisitor.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. if (typeof b !== "function" && b !== null)
  11. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  12. extendStatics(d, b);
  13. function __() { this.constructor = d; }
  14. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15. };
  16. })();
  17. Object.defineProperty(exports, "__esModule", { value: true });
  18. exports.MmlVisitor = void 0;
  19. var SerializedMmlVisitor_js_1 = require("../../core/MmlTree/SerializedMmlVisitor.js");
  20. var Options_js_1 = require("../../util/Options.js");
  21. var MmlVisitor = (function (_super) {
  22. __extends(MmlVisitor, _super);
  23. function MmlVisitor() {
  24. var _this = _super !== null && _super.apply(this, arguments) || this;
  25. _this.options = {
  26. texHints: true,
  27. semantics: false,
  28. };
  29. _this.mathItem = null;
  30. return _this;
  31. }
  32. MmlVisitor.prototype.visitTree = function (node, math, options) {
  33. if (math === void 0) { math = null; }
  34. if (options === void 0) { options = {}; }
  35. this.mathItem = math;
  36. (0, Options_js_1.userOptions)(this.options, options);
  37. return this.visitNode(node, '');
  38. };
  39. MmlVisitor.prototype.visitTeXAtomNode = function (node, space) {
  40. if (this.options.texHints) {
  41. return _super.prototype.visitTeXAtomNode.call(this, node, space);
  42. }
  43. if (node.childNodes[0] && node.childNodes[0].childNodes.length === 1) {
  44. return this.visitNode(node.childNodes[0], space);
  45. }
  46. return space + '<mrow' + this.getAttributes(node) + '>\n'
  47. + this.childNodeMml(node, space + ' ', '\n')
  48. + space + '</mrow>';
  49. };
  50. MmlVisitor.prototype.visitMathNode = function (node, space) {
  51. if (!this.options.semantics || this.mathItem.inputJax.name !== 'TeX') {
  52. return _super.prototype.visitDefault.call(this, node, space);
  53. }
  54. var addRow = node.childNodes.length && node.childNodes[0].childNodes.length > 1;
  55. return space + '<math' + this.getAttributes(node) + '>\n'
  56. + space + ' <semantics>\n'
  57. + (addRow ? space + ' <mrow>\n' : '')
  58. + this.childNodeMml(node, space + (addRow ? ' ' : ' '), '\n')
  59. + (addRow ? space + ' </mrow>\n' : '')
  60. + space + ' <annotation encoding="application/x-tex">' + this.mathItem.math + '</annotation>\n'
  61. + space + ' </semantics>\n'
  62. + space + '</math>';
  63. };
  64. return MmlVisitor;
  65. }(SerializedMmlVisitor_js_1.SerializedMmlVisitor));
  66. exports.MmlVisitor = MmlVisitor;
  67. //# sourceMappingURL=MmlVisitor.js.map