@umoteam/editor-external 10.0.0 → 10.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,13 +37,13 @@ Try out KaTeX [on the demo page](https://katex.org/#demo)!
37
37
  <!-- KaTeX requires the use of the HTML5 doctype. Without it, KaTeX may not render properly -->
38
38
  <html>
39
39
  <head>
40
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css" integrity="sha384-nB0miv6/jRmo5UMMR1wu3Gz6NLsoTkbqJghGIsx//Rlm+ZU03BU6SQNC66uf4l5+" crossorigin="anonymous">
40
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.38/dist/katex.min.css" integrity="sha384-/L6i+LN3dyoaK2jYG5ZLh5u13cjdsPDcFOSNJeFBFa/KgVXR5kOfTdiN3ft1uMAq" crossorigin="anonymous">
41
41
 
42
42
  <!-- The loading of KaTeX is deferred to speed up page rendering -->
43
- <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js" integrity="sha384-7zkQWkzuo3B5mTepMUcHkMB5jZaolc2xDwL6VFqjFALcbeS9Ggm/Yr2r3Dy4lfFg" crossorigin="anonymous"></script>
43
+ <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.38/dist/katex.min.js" integrity="sha384-H6s1ZrH2CKpFpqR680poRdStIRJGXty7fSkxAcIfxwl9iu6A4BOPtTk7vQ58Ovio" crossorigin="anonymous"></script>
44
44
 
45
45
  <!-- To automatically render math in text elements, include the auto-render extension: -->
46
- <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/contrib/auto-render.min.js" integrity="sha384-43gviWU0YVjaDtb/GhzOouOXtZMP/7XUzwPTstBeZFe/+rCMvRwr4yROQP43s0Xk" crossorigin="anonymous"
46
+ <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.38/dist/contrib/auto-render.min.js" integrity="sha384-bjyGPfbij8/NDKJhSGZNP/khQVgtHUE5exjm4Ydllo42FwIgYsdLO2lXGmRBf5Mz" crossorigin="anonymous"
47
47
  onload="renderMathInElement(document.body);"></script>
48
48
  </head>
49
49
  ...
@@ -7,15 +7,15 @@
7
7
  exports["renderMathInElement"] = factory(require("katex"));
8
8
  else
9
9
  root["renderMathInElement"] = factory(root["katex"]);
10
- })((typeof self !== 'undefined' ? self : this), function(__WEBPACK_EXTERNAL_MODULE__771__) {
10
+ })((typeof self !== 'undefined' ? self : this), function(__WEBPACK_EXTERNAL_MODULE__757__) {
11
11
  return /******/ (function() { // webpackBootstrap
12
12
  /******/ "use strict";
13
13
  /******/ var __webpack_modules__ = ({
14
14
 
15
- /***/ 771:
15
+ /***/ 757:
16
16
  /***/ (function(module) {
17
17
 
18
- module.exports = __WEBPACK_EXTERNAL_MODULE__771__;
18
+ module.exports = __WEBPACK_EXTERNAL_MODULE__757__;
19
19
 
20
20
  /***/ })
21
21
 
@@ -77,8 +77,6 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__771__;
77
77
  /******/
78
78
  /************************************************************************/
79
79
  var __webpack_exports__ = {};
80
- // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
81
- !function() {
82
80
 
83
81
  // EXPORTS
84
82
  __webpack_require__.d(__webpack_exports__, {
@@ -86,20 +84,19 @@ __webpack_require__.d(__webpack_exports__, {
86
84
  });
87
85
 
88
86
  // EXTERNAL MODULE: external "katex"
89
- var external_katex_ = __webpack_require__(771);
87
+ var external_katex_ = __webpack_require__(757);
90
88
  var external_katex_default = /*#__PURE__*/__webpack_require__.n(external_katex_);
91
- ;// CONCATENATED MODULE: ./contrib/auto-render/splitAtDelimiters.js
89
+ ;// ./contrib/auto-render/splitAtDelimiters.ts
92
90
  /* eslint no-constant-condition:0 */
91
+
93
92
  const findEndOfMath = function (delimiter, text, startIndex) {
94
93
  // Adapted from
95
94
  // https://github.com/Khan/perseus/blob/master/src/perseus-markdown.jsx
96
95
  let index = startIndex;
97
96
  let braceLevel = 0;
98
97
  const delimLength = delimiter.length;
99
-
100
98
  while (index < text.length) {
101
99
  const character = text[index];
102
-
103
100
  if (braceLevel <= 0 && text.slice(index, index + delimLength) === delimiter) {
104
101
  return index;
105
102
  } else if (character === "\\") {
@@ -109,47 +106,36 @@ const findEndOfMath = function (delimiter, text, startIndex) {
109
106
  } else if (character === "}") {
110
107
  braceLevel--;
111
108
  }
112
-
113
109
  index++;
114
110
  }
115
-
116
111
  return -1;
117
112
  };
118
-
119
113
  const escapeRegex = function (string) {
120
114
  return string.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
121
115
  };
122
-
123
116
  const amsRegex = /^\\begin{/;
124
-
125
117
  const splitAtDelimiters = function (text, delimiters) {
126
118
  let index;
127
119
  const data = [];
128
120
  const regexLeft = new RegExp("(" + delimiters.map(x => escapeRegex(x.left)).join("|") + ")");
129
-
130
121
  while (true) {
131
122
  index = text.search(regexLeft);
132
-
133
123
  if (index === -1) {
134
124
  break;
135
125
  }
136
-
137
126
  if (index > 0) {
138
127
  data.push({
139
128
  type: "text",
140
129
  data: text.slice(0, index)
141
130
  });
142
131
  text = text.slice(index); // now text starts with delimiter
143
- } // ... so this always succeeds:
144
-
145
-
132
+ }
133
+ // ... so this always succeeds:
146
134
  const i = delimiters.findIndex(delim => text.startsWith(delim.left));
147
135
  index = findEndOfMath(delimiters[i].right, text, delimiters[i].left.length);
148
-
149
136
  if (index === -1) {
150
137
  break;
151
138
  }
152
-
153
139
  const rawData = text.slice(0, index + delimiters[i].right.length);
154
140
  const math = amsRegex.test(rawData) ? rawData : text.slice(delimiters[i].left.length, index);
155
141
  data.push({
@@ -160,98 +146,83 @@ const splitAtDelimiters = function (text, delimiters) {
160
146
  });
161
147
  text = text.slice(index + delimiters[i].right.length);
162
148
  }
163
-
164
149
  if (text !== "") {
165
150
  data.push({
166
151
  type: "text",
167
152
  data: text
168
153
  });
169
154
  }
170
-
171
155
  return data;
172
156
  };
173
-
174
157
  /* harmony default export */ var auto_render_splitAtDelimiters = (splitAtDelimiters);
175
- ;// CONCATENATED MODULE: ./contrib/auto-render/auto-render.js
158
+ ;// ./contrib/auto-render/auto-render.ts
176
159
  /* eslint no-console:0 */
177
160
 
178
161
 
162
+
179
163
  /* Note: optionsCopy is mutated by this method. If it is ever exposed in the
180
164
  * API, we should copy it before mutating.
181
165
  */
182
-
183
166
  const renderMathInText = function (text, optionsCopy) {
184
167
  const data = auto_render_splitAtDelimiters(text, optionsCopy.delimiters);
185
-
186
168
  if (data.length === 1 && data[0].type === 'text') {
187
169
  // There is no formula in the text.
188
170
  // Let's return null which means there is no need to replace
189
171
  // the current text node with a new one.
190
172
  return null;
191
173
  }
192
-
193
174
  const fragment = document.createDocumentFragment();
194
-
195
175
  for (let i = 0; i < data.length; i++) {
196
176
  if (data[i].type === "text") {
197
177
  fragment.appendChild(document.createTextNode(data[i].data));
198
178
  } else {
199
179
  const span = document.createElement("span");
200
- let math = data[i].data; // Override any display mode defined in the settings with that
180
+ let math = data[i].data;
181
+ // Override any display mode defined in the settings with that
201
182
  // defined by the text itself
202
-
203
183
  optionsCopy.displayMode = data[i].display;
204
-
205
184
  try {
206
185
  if (optionsCopy.preProcess) {
207
186
  math = optionsCopy.preProcess(math);
208
187
  }
209
-
210
188
  external_katex_default().render(math, span, optionsCopy);
211
189
  } catch (e) {
212
190
  if (!(e instanceof (external_katex_default()).ParseError)) {
213
191
  throw e;
214
192
  }
215
-
216
193
  optionsCopy.errorCallback("KaTeX auto-render: Failed to parse `" + data[i].data + "` with ", e);
217
194
  fragment.appendChild(document.createTextNode(data[i].rawData));
218
195
  continue;
219
196
  }
220
-
221
197
  fragment.appendChild(span);
222
198
  }
223
199
  }
224
-
225
200
  return fragment;
226
201
  };
227
-
228
202
  const renderElem = function (elem, optionsCopy) {
229
203
  for (let i = 0; i < elem.childNodes.length; i++) {
230
204
  const childNode = elem.childNodes[i];
231
-
232
205
  if (childNode.nodeType === 3) {
206
+ var _childNode$textConten;
233
207
  // Text node
234
208
  // Concatenate all sibling text nodes.
235
209
  // Webkit browsers split very large text nodes into smaller ones,
236
210
  // so the delimiters may be split across different nodes.
237
- let textContentConcat = childNode.textContent;
211
+ let textContentConcat = (_childNode$textConten = childNode.textContent) != null ? _childNode$textConten : "";
238
212
  let sibling = childNode.nextSibling;
239
213
  let nSiblings = 0;
240
-
241
214
  while (sibling && sibling.nodeType === Node.TEXT_NODE) {
242
- textContentConcat += sibling.textContent;
215
+ var _sibling$textContent;
216
+ textContentConcat += (_sibling$textContent = sibling.textContent) != null ? _sibling$textContent : "";
243
217
  sibling = sibling.nextSibling;
244
218
  nSiblings++;
245
219
  }
246
-
247
220
  const frag = renderMathInText(textContentConcat, optionsCopy);
248
-
249
221
  if (frag) {
250
222
  // Remove extra text nodes
251
223
  for (let j = 0; j < nSiblings; j++) {
252
224
  childNode.nextSibling.remove();
253
225
  }
254
-
255
226
  i += frag.childNodes.length - 1;
256
227
  elem.replaceChild(frag, childNode);
257
228
  } else {
@@ -262,30 +233,22 @@ const renderElem = function (elem, optionsCopy) {
262
233
  } else if (childNode.nodeType === 1) {
263
234
  // Element node
264
235
  const className = ' ' + childNode.className + ' ';
265
- const shouldRender = optionsCopy.ignoredTags.indexOf(childNode.nodeName.toLowerCase()) === -1 && optionsCopy.ignoredClasses.every(x => className.indexOf(' ' + x + ' ') === -1);
266
-
236
+ const shouldRender = !optionsCopy.ignoredTags.has(childNode.nodeName.toLowerCase()) && optionsCopy.ignoredClasses.every(x => !className.includes(' ' + x + ' '));
267
237
  if (shouldRender) {
268
238
  renderElem(childNode, optionsCopy);
269
239
  }
270
- } // Otherwise, it's something else, and ignore it.
271
-
240
+ }
241
+ // Otherwise, it's something else, and ignore it.
272
242
  }
273
243
  };
274
-
275
244
  const renderMathInElement = function (elem, options) {
276
245
  if (!elem) {
277
246
  throw new Error("No element provided to render");
278
247
  }
248
+ const optionsCopy = {};
249
+ Object.assign(optionsCopy, options);
279
250
 
280
- const optionsCopy = {}; // Object.assign(optionsCopy, option)
281
-
282
- for (const option in options) {
283
- if (options.hasOwnProperty(option)) {
284
- optionsCopy[option] = options[option];
285
- }
286
- } // default options
287
-
288
-
251
+ // default options
289
252
  optionsCopy.delimiters = optionsCopy.delimiters || [{
290
253
  left: "$$",
291
254
  right: "$$",
@@ -294,9 +257,11 @@ const renderMathInElement = function (elem, options) {
294
257
  left: "\\(",
295
258
  right: "\\)",
296
259
  display: false
297
- }, // LaTeX uses $…$, but it ruins the display of normal `$` in text:
260
+ },
261
+ // LaTeX uses $…$, but it ruins the display of normal `$` in text:
298
262
  // {left: "$", right: "$", display: false},
299
263
  // $ must come after $$
264
+
300
265
  // Render AMS environments even if outside $$…$$ delimiters.
301
266
  {
302
267
  left: "\\begin{equation}",
@@ -323,17 +288,16 @@ const renderMathInElement = function (elem, options) {
323
288
  right: "\\]",
324
289
  display: true
325
290
  }];
326
- optionsCopy.ignoredTags = optionsCopy.ignoredTags || ["script", "noscript", "style", "textarea", "pre", "code", "option"];
291
+ optionsCopy.ignoredTags = new Set((options == null ? void 0 : options.ignoredTags) || ["script", "noscript", "style", "textarea", "pre", "code", "option"]);
327
292
  optionsCopy.ignoredClasses = optionsCopy.ignoredClasses || [];
328
- optionsCopy.errorCallback = optionsCopy.errorCallback || console.error; // Enable sharing of global macros defined via `\gdef` between different
329
- // math elements within a single call to `renderMathInElement`.
293
+ optionsCopy.errorCallback = optionsCopy.errorCallback || console.error;
330
294
 
295
+ // Enable sharing of global macros defined via `\gdef` between different
296
+ // math elements within a single call to `renderMathInElement`.
331
297
  optionsCopy.macros = optionsCopy.macros || {};
332
298
  renderElem(elem, optionsCopy);
333
299
  };
334
-
335
300
  /* harmony default export */ var auto_render = (renderMathInElement);
336
- }();
337
301
  __webpack_exports__ = __webpack_exports__["default"];
338
302
  /******/ return __webpack_exports__;
339
303
  /******/ })()
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("katex")):"function"==typeof define&&define.amd?define(["katex"],t):"object"==typeof exports?exports.renderMathInElement=t(require("katex")):e.renderMathInElement=t(e.katex)}("undefined"!=typeof self?self:this,(function(e){return function(){"use strict";var t={771:function(t){t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)};var o={};return function(){r.d(o,{default:function(){return d}});var e=r(771),t=r.n(e);const n=function(e,t,n){let r=n,o=0;const i=e.length;for(;r<t.length;){const n=t[r];if(o<=0&&t.slice(r,r+i)===e)return r;"\\"===n?r++:"{"===n?o++:"}"===n&&o--,r++}return-1},i=/^\\begin{/;var a=function(e,t){let r;const o=[],a=new RegExp("("+t.map((e=>e.left.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&"))).join("|")+")");for(;r=e.search(a),-1!==r;){r>0&&(o.push({type:"text",data:e.slice(0,r)}),e=e.slice(r));const a=t.findIndex((t=>e.startsWith(t.left)));if(r=n(t[a].right,e,t[a].left.length),-1===r)break;const l=e.slice(0,r+t[a].right.length),s=i.test(l)?l:e.slice(t[a].left.length,r);o.push({type:"math",data:s,rawData:l,display:t[a].display}),e=e.slice(r+t[a].right.length)}return""!==e&&o.push({type:"text",data:e}),o};const l=function(e,n){const r=a(e,n.delimiters);if(1===r.length&&"text"===r[0].type)return null;const o=document.createDocumentFragment();for(let e=0;e<r.length;e++)if("text"===r[e].type)o.appendChild(document.createTextNode(r[e].data));else{const i=document.createElement("span");let a=r[e].data;n.displayMode=r[e].display;try{n.preProcess&&(a=n.preProcess(a)),t().render(a,i,n)}catch(i){if(!(i instanceof t().ParseError))throw i;n.errorCallback("KaTeX auto-render: Failed to parse `"+r[e].data+"` with ",i),o.appendChild(document.createTextNode(r[e].rawData));continue}o.appendChild(i)}return o},s=function(e,t){for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(3===r.nodeType){let o=r.textContent,i=r.nextSibling,a=0;for(;i&&i.nodeType===Node.TEXT_NODE;)o+=i.textContent,i=i.nextSibling,a++;const s=l(o,t);if(s){for(let e=0;e<a;e++)r.nextSibling.remove();n+=s.childNodes.length-1,e.replaceChild(s,r)}else n+=a}else if(1===r.nodeType){const e=" "+r.className+" ";-1===t.ignoredTags.indexOf(r.nodeName.toLowerCase())&&t.ignoredClasses.every((t=>-1===e.indexOf(" "+t+" ")))&&s(r,t)}}};var d=function(e,t){if(!e)throw new Error("No element provided to render");const n={};for(const e in t)t.hasOwnProperty(e)&&(n[e]=t[e]);n.delimiters=n.delimiters||[{left:"$$",right:"$$",display:!0},{left:"\\(",right:"\\)",display:!1},{left:"\\begin{equation}",right:"\\end{equation}",display:!0},{left:"\\begin{align}",right:"\\end{align}",display:!0},{left:"\\begin{alignat}",right:"\\end{alignat}",display:!0},{left:"\\begin{gather}",right:"\\end{gather}",display:!0},{left:"\\begin{CD}",right:"\\end{CD}",display:!0},{left:"\\[",right:"\\]",display:!0}],n.ignoredTags=n.ignoredTags||["script","noscript","style","textarea","pre","code","option"],n.ignoredClasses=n.ignoredClasses||[],n.errorCallback=n.errorCallback||console.error,n.macros=n.macros||{},s(e,n)}}(),o=o.default}()}));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("katex")):"function"==typeof define&&define.amd?define(["katex"],t):"object"==typeof exports?exports.renderMathInElement=t(require("katex")):e.renderMathInElement=t(e.katex)}("undefined"!=typeof self?self:this,function(e){return function(){"use strict";var t={757:function(t){t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)};var o={};r.d(o,{default:function(){return p}});var i=r(757),a=r.n(i);const l=function(e,t,n){let r=n,o=0;const i=e.length;for(;r<t.length;){const n=t[r];if(o<=0&&t.slice(r,r+i)===e)return r;"\\"===n?r++:"{"===n?o++:"}"===n&&o--,r++}return-1},s=/^\\begin{/;var d=function(e,t){let n;const r=[],o=new RegExp("("+t.map(e=>e.left.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")).join("|")+")");for(;n=e.search(o),-1!==n;){n>0&&(r.push({type:"text",data:e.slice(0,n)}),e=e.slice(n));const o=t.findIndex(t=>e.startsWith(t.left));if(n=l(t[o].right,e,t[o].left.length),-1===n)break;const i=e.slice(0,n+t[o].right.length),a=s.test(i)?i:e.slice(t[o].left.length,n);r.push({type:"math",data:a,rawData:i,display:t[o].display}),e=e.slice(n+t[o].right.length)}return""!==e&&r.push({type:"text",data:e}),r};const c=function(e,t){const n=d(e,t.delimiters);if(1===n.length&&"text"===n[0].type)return null;const r=document.createDocumentFragment();for(let e=0;e<n.length;e++)if("text"===n[e].type)r.appendChild(document.createTextNode(n[e].data));else{const o=document.createElement("span");let i=n[e].data;t.displayMode=n[e].display;try{t.preProcess&&(i=t.preProcess(i)),a().render(i,o,t)}catch(o){if(!(o instanceof a().ParseError))throw o;t.errorCallback("KaTeX auto-render: Failed to parse `"+n[e].data+"` with ",o),r.appendChild(document.createTextNode(n[e].rawData));continue}r.appendChild(o)}return r},f=function(e,t){for(let o=0;o<e.childNodes.length;o++){const i=e.childNodes[o];if(3===i.nodeType){var n;let a=null!=(n=i.textContent)?n:"",l=i.nextSibling,s=0;for(;l&&l.nodeType===Node.TEXT_NODE;){var r;a+=null!=(r=l.textContent)?r:"",l=l.nextSibling,s++}const d=c(a,t);if(d){for(let e=0;e<s;e++)i.nextSibling.remove();o+=d.childNodes.length-1,e.replaceChild(d,i)}else o+=s}else if(1===i.nodeType){const e=" "+i.className+" ";!t.ignoredTags.has(i.nodeName.toLowerCase())&&t.ignoredClasses.every(t=>!e.includes(" "+t+" "))&&f(i,t)}}};var p=function(e,t){if(!e)throw new Error("No element provided to render");const n={};Object.assign(n,t),n.delimiters=n.delimiters||[{left:"$$",right:"$$",display:!0},{left:"\\(",right:"\\)",display:!1},{left:"\\begin{equation}",right:"\\end{equation}",display:!0},{left:"\\begin{align}",right:"\\end{align}",display:!0},{left:"\\begin{alignat}",right:"\\end{alignat}",display:!0},{left:"\\begin{gather}",right:"\\end{gather}",display:!0},{left:"\\begin{CD}",right:"\\end{CD}",display:!0},{left:"\\[",right:"\\]",display:!0}],n.ignoredTags=new Set((null==t?void 0:t.ignoredTags)||["script","noscript","style","textarea","pre","code","option"]),n.ignoredClasses=n.ignoredClasses||[],n.errorCallback=n.errorCallback||console.error,n.macros=n.macros||{},f(e,n)};return o=o.default}()});
@@ -7,10 +7,8 @@ var findEndOfMath = function findEndOfMath(delimiter, text, startIndex) {
7
7
  var index = startIndex;
8
8
  var braceLevel = 0;
9
9
  var delimLength = delimiter.length;
10
-
11
10
  while (index < text.length) {
12
11
  var character = text[index];
13
-
14
12
  if (braceLevel <= 0 && text.slice(index, index + delimLength) === delimiter) {
15
13
  return index;
16
14
  } else if (character === "\\") {
@@ -20,47 +18,36 @@ var findEndOfMath = function findEndOfMath(delimiter, text, startIndex) {
20
18
  } else if (character === "}") {
21
19
  braceLevel--;
22
20
  }
23
-
24
21
  index++;
25
22
  }
26
-
27
23
  return -1;
28
24
  };
29
-
30
25
  var escapeRegex = function escapeRegex(string) {
31
26
  return string.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
32
27
  };
33
-
34
28
  var amsRegex = /^\\begin{/;
35
-
36
29
  var splitAtDelimiters = function splitAtDelimiters(text, delimiters) {
37
30
  var index;
38
31
  var data = [];
39
32
  var regexLeft = new RegExp("(" + delimiters.map(x => escapeRegex(x.left)).join("|") + ")");
40
-
41
33
  while (true) {
42
34
  index = text.search(regexLeft);
43
-
44
35
  if (index === -1) {
45
36
  break;
46
37
  }
47
-
48
38
  if (index > 0) {
49
39
  data.push({
50
40
  type: "text",
51
41
  data: text.slice(0, index)
52
42
  });
53
43
  text = text.slice(index); // now text starts with delimiter
54
- } // ... so this always succeeds:
55
-
56
-
44
+ }
45
+ // ... so this always succeeds:
57
46
  var i = delimiters.findIndex(delim => text.startsWith(delim.left));
58
47
  index = findEndOfMath(delimiters[i].right, text, delimiters[i].left.length);
59
-
60
48
  if (index === -1) {
61
49
  break;
62
50
  }
63
-
64
51
  var rawData = text.slice(0, index + delimiters[i].right.length);
65
52
  var math = amsRegex.test(rawData) ? rawData : text.slice(delimiters[i].left.length, index);
66
53
  data.push({
@@ -71,14 +58,12 @@ var splitAtDelimiters = function splitAtDelimiters(text, delimiters) {
71
58
  });
72
59
  text = text.slice(index + delimiters[i].right.length);
73
60
  }
74
-
75
61
  if (text !== "") {
76
62
  data.push({
77
63
  type: "text",
78
64
  data: text
79
65
  });
80
66
  }
81
-
82
67
  return data;
83
68
  };
84
69
 
@@ -86,115 +71,95 @@ var splitAtDelimiters = function splitAtDelimiters(text, delimiters) {
86
71
  /* Note: optionsCopy is mutated by this method. If it is ever exposed in the
87
72
  * API, we should copy it before mutating.
88
73
  */
89
-
90
74
  var renderMathInText = function renderMathInText(text, optionsCopy) {
91
75
  var data = splitAtDelimiters(text, optionsCopy.delimiters);
92
-
93
76
  if (data.length === 1 && data[0].type === 'text') {
94
77
  // There is no formula in the text.
95
78
  // Let's return null which means there is no need to replace
96
79
  // the current text node with a new one.
97
80
  return null;
98
81
  }
99
-
100
82
  var fragment = document.createDocumentFragment();
101
-
102
83
  for (var i = 0; i < data.length; i++) {
103
84
  if (data[i].type === "text") {
104
85
  fragment.appendChild(document.createTextNode(data[i].data));
105
86
  } else {
106
87
  var span = document.createElement("span");
107
- var math = data[i].data; // Override any display mode defined in the settings with that
88
+ var math = data[i].data;
89
+ // Override any display mode defined in the settings with that
108
90
  // defined by the text itself
109
-
110
91
  optionsCopy.displayMode = data[i].display;
111
-
112
92
  try {
113
93
  if (optionsCopy.preProcess) {
114
94
  math = optionsCopy.preProcess(math);
115
95
  }
116
-
117
96
  katex.render(math, span, optionsCopy);
118
97
  } catch (e) {
119
98
  if (!(e instanceof katex.ParseError)) {
120
99
  throw e;
121
100
  }
122
-
123
101
  optionsCopy.errorCallback("KaTeX auto-render: Failed to parse `" + data[i].data + "` with ", e);
124
102
  fragment.appendChild(document.createTextNode(data[i].rawData));
125
103
  continue;
126
104
  }
127
-
128
105
  fragment.appendChild(span);
129
106
  }
130
107
  }
131
-
132
108
  return fragment;
133
109
  };
134
-
135
- var renderElem = function renderElem(elem, optionsCopy) {
136
- for (var i = 0; i < elem.childNodes.length; i++) {
137
- var childNode = elem.childNodes[i];
138
-
110
+ var _renderElem = function renderElem(elem, optionsCopy) {
111
+ var _loop = function _loop(_i) {
112
+ var childNode = elem.childNodes[_i];
139
113
  if (childNode.nodeType === 3) {
114
+ var _childNode$textConten;
140
115
  // Text node
141
116
  // Concatenate all sibling text nodes.
142
117
  // Webkit browsers split very large text nodes into smaller ones,
143
118
  // so the delimiters may be split across different nodes.
144
- var textContentConcat = childNode.textContent;
119
+ var textContentConcat = (_childNode$textConten = childNode.textContent) != null ? _childNode$textConten : "";
145
120
  var sibling = childNode.nextSibling;
146
121
  var nSiblings = 0;
147
-
148
122
  while (sibling && sibling.nodeType === Node.TEXT_NODE) {
149
- textContentConcat += sibling.textContent;
123
+ var _sibling$textContent;
124
+ textContentConcat += (_sibling$textContent = sibling.textContent) != null ? _sibling$textContent : "";
150
125
  sibling = sibling.nextSibling;
151
126
  nSiblings++;
152
127
  }
153
-
154
128
  var frag = renderMathInText(textContentConcat, optionsCopy);
155
-
156
129
  if (frag) {
157
130
  // Remove extra text nodes
158
131
  for (var j = 0; j < nSiblings; j++) {
159
132
  childNode.nextSibling.remove();
160
133
  }
161
-
162
- i += frag.childNodes.length - 1;
134
+ _i += frag.childNodes.length - 1;
163
135
  elem.replaceChild(frag, childNode);
164
136
  } else {
165
137
  // If the concatenated text does not contain math
166
138
  // the siblings will not either
167
- i += nSiblings;
139
+ _i += nSiblings;
168
140
  }
169
141
  } else if (childNode.nodeType === 1) {
170
- (function () {
171
- // Element node
172
- var className = ' ' + childNode.className + ' ';
173
- var shouldRender = optionsCopy.ignoredTags.indexOf(childNode.nodeName.toLowerCase()) === -1 && optionsCopy.ignoredClasses.every(x => className.indexOf(' ' + x + ' ') === -1);
174
-
175
- if (shouldRender) {
176
- renderElem(childNode, optionsCopy);
177
- }
178
- })();
179
- } // Otherwise, it's something else, and ignore it.
180
-
142
+ // Element node
143
+ var className = ' ' + childNode.className + ' ';
144
+ var shouldRender = !optionsCopy.ignoredTags.has(childNode.nodeName.toLowerCase()) && optionsCopy.ignoredClasses.every(x => !className.includes(' ' + x + ' '));
145
+ if (shouldRender) {
146
+ _renderElem(childNode, optionsCopy);
147
+ }
148
+ }
149
+ // Otherwise, it's something else, and ignore it.
150
+ i = _i;
151
+ };
152
+ for (var i = 0; i < elem.childNodes.length; i++) {
153
+ _loop(i);
181
154
  }
182
155
  };
183
-
184
156
  var renderMathInElement = function renderMathInElement(elem, options) {
185
157
  if (!elem) {
186
158
  throw new Error("No element provided to render");
187
159
  }
188
-
189
- var optionsCopy = {}; // Object.assign(optionsCopy, option)
190
-
191
- for (var option in options) {
192
- if (options.hasOwnProperty(option)) {
193
- optionsCopy[option] = options[option];
194
- }
195
- } // default options
196
-
197
-
160
+ var optionsCopy = {};
161
+ Object.assign(optionsCopy, options);
162
+ // default options
198
163
  optionsCopy.delimiters = optionsCopy.delimiters || [{
199
164
  left: "$$",
200
165
  right: "$$",
@@ -203,7 +168,8 @@ var renderMathInElement = function renderMathInElement(elem, options) {
203
168
  left: "\\(",
204
169
  right: "\\)",
205
170
  display: false
206
- }, // LaTeX uses $…$, but it ruins the display of normal `$` in text:
171
+ },
172
+ // LaTeX uses $…$, but it ruins the display of normal `$` in text:
207
173
  // {left: "$", right: "$", display: false},
208
174
  // $ must come after $$
209
175
  // Render AMS environments even if outside $$…$$ delimiters.
@@ -232,13 +198,13 @@ var renderMathInElement = function renderMathInElement(elem, options) {
232
198
  right: "\\]",
233
199
  display: true
234
200
  }];
235
- optionsCopy.ignoredTags = optionsCopy.ignoredTags || ["script", "noscript", "style", "textarea", "pre", "code", "option"];
201
+ optionsCopy.ignoredTags = new Set((options == null ? void 0 : options.ignoredTags) || ["script", "noscript", "style", "textarea", "pre", "code", "option"]);
236
202
  optionsCopy.ignoredClasses = optionsCopy.ignoredClasses || [];
237
- optionsCopy.errorCallback = optionsCopy.errorCallback || console.error; // Enable sharing of global macros defined via `\gdef` between different
203
+ optionsCopy.errorCallback = optionsCopy.errorCallback || console.error;
204
+ // Enable sharing of global macros defined via `\gdef` between different
238
205
  // math elements within a single call to `renderMathInElement`.
239
-
240
206
  optionsCopy.macros = optionsCopy.macros || {};
241
- renderElem(elem, optionsCopy);
207
+ _renderElem(elem, optionsCopy);
242
208
  };
243
209
 
244
210
  export { renderMathInElement as default };