FindMathML.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. var __values = (this && this.__values) || function(o) {
  18. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  19. if (m) return m.call(o);
  20. if (o && typeof o.length === "number") return {
  21. next: function () {
  22. if (o && i >= o.length) o = void 0;
  23. return { value: o && o[i++], done: !o };
  24. }
  25. };
  26. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  27. };
  28. Object.defineProperty(exports, "__esModule", { value: true });
  29. exports.FindMathML = void 0;
  30. var FindMath_js_1 = require("../../core/FindMath.js");
  31. var NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
  32. var FindMathML = (function (_super) {
  33. __extends(FindMathML, _super);
  34. function FindMathML() {
  35. return _super !== null && _super.apply(this, arguments) || this;
  36. }
  37. FindMathML.prototype.findMath = function (node) {
  38. var set = new Set();
  39. this.findMathNodes(node, set);
  40. this.findMathPrefixed(node, set);
  41. var html = this.adaptor.root(this.adaptor.document);
  42. if (this.adaptor.kind(html) === 'html' && set.size === 0) {
  43. this.findMathNS(node, set);
  44. }
  45. return this.processMath(set);
  46. };
  47. FindMathML.prototype.findMathNodes = function (node, set) {
  48. var e_1, _a;
  49. try {
  50. for (var _b = __values(this.adaptor.tags(node, 'math')), _c = _b.next(); !_c.done; _c = _b.next()) {
  51. var math = _c.value;
  52. set.add(math);
  53. }
  54. }
  55. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  56. finally {
  57. try {
  58. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  59. }
  60. finally { if (e_1) throw e_1.error; }
  61. }
  62. };
  63. FindMathML.prototype.findMathPrefixed = function (node, set) {
  64. var e_2, _a, e_3, _b;
  65. var html = this.adaptor.root(this.adaptor.document);
  66. try {
  67. for (var _c = __values(this.adaptor.allAttributes(html)), _d = _c.next(); !_d.done; _d = _c.next()) {
  68. var attr = _d.value;
  69. if (attr.name.substr(0, 6) === 'xmlns:' && attr.value === NAMESPACE) {
  70. var prefix = attr.name.substr(6);
  71. try {
  72. for (var _e = (e_3 = void 0, __values(this.adaptor.tags(node, prefix + ':math'))), _f = _e.next(); !_f.done; _f = _e.next()) {
  73. var math = _f.value;
  74. set.add(math);
  75. }
  76. }
  77. catch (e_3_1) { e_3 = { error: e_3_1 }; }
  78. finally {
  79. try {
  80. if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
  81. }
  82. finally { if (e_3) throw e_3.error; }
  83. }
  84. }
  85. }
  86. }
  87. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  88. finally {
  89. try {
  90. if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
  91. }
  92. finally { if (e_2) throw e_2.error; }
  93. }
  94. };
  95. FindMathML.prototype.findMathNS = function (node, set) {
  96. var e_4, _a;
  97. try {
  98. for (var _b = __values(this.adaptor.tags(node, 'math', NAMESPACE)), _c = _b.next(); !_c.done; _c = _b.next()) {
  99. var math = _c.value;
  100. set.add(math);
  101. }
  102. }
  103. catch (e_4_1) { e_4 = { error: e_4_1 }; }
  104. finally {
  105. try {
  106. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  107. }
  108. finally { if (e_4) throw e_4.error; }
  109. }
  110. };
  111. FindMathML.prototype.processMath = function (set) {
  112. var e_5, _a;
  113. var math = [];
  114. try {
  115. for (var _b = __values(Array.from(set)), _c = _b.next(); !_c.done; _c = _b.next()) {
  116. var mml = _c.value;
  117. var display = (this.adaptor.getAttribute(mml, 'display') === 'block' ||
  118. this.adaptor.getAttribute(mml, 'mode') === 'display');
  119. var start = { node: mml, n: 0, delim: '' };
  120. var end = { node: mml, n: 0, delim: '' };
  121. math.push({ math: this.adaptor.outerHTML(mml), start: start, end: end, display: display });
  122. }
  123. }
  124. catch (e_5_1) { e_5 = { error: e_5_1 }; }
  125. finally {
  126. try {
  127. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  128. }
  129. finally { if (e_5) throw e_5.error; }
  130. }
  131. return math;
  132. };
  133. FindMathML.OPTIONS = {};
  134. return FindMathML;
  135. }(FindMath_js_1.AbstractFindMath));
  136. exports.FindMathML = FindMathML;
  137. //# sourceMappingURL=FindMathML.js.map