1 | (function webpackUniversalModuleDefinition(root, factory) {
|
2 | if(typeof exports === 'object' && typeof module === 'object')
|
3 | module.exports = factory(require("katex"));
|
4 | else if(typeof define === 'function' && define.amd)
|
5 | define(["katex"], factory);
|
6 | else if(typeof exports === 'object')
|
7 | exports["renderMathInElement"] = factory(require("katex"));
|
8 | else
|
9 | root["renderMathInElement"] = factory(root["katex"]);
|
10 | })((typeof self !== 'undefined' ? self : this), function(__WEBPACK_EXTERNAL_MODULE__0__) {
|
11 | return (function(modules) {
|
12 |
|
13 | var installedModules = {};
|
14 |
|
15 |
|
16 | function __webpack_require__(moduleId) {
|
17 |
|
18 |
|
19 | if(installedModules[moduleId]) {
|
20 | return installedModules[moduleId].exports;
|
21 | }
|
22 |
|
23 | var module = installedModules[moduleId] = {
|
24 | i: moduleId,
|
25 | l: false,
|
26 | exports: {}
|
27 | };
|
28 |
|
29 |
|
30 | modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
31 |
|
32 |
|
33 | module.l = true;
|
34 |
|
35 |
|
36 | return module.exports;
|
37 | }
|
38 |
|
39 |
|
40 |
|
41 | __webpack_require__.m = modules;
|
42 |
|
43 |
|
44 | __webpack_require__.c = installedModules;
|
45 |
|
46 |
|
47 | __webpack_require__.d = function(exports, name, getter) {
|
48 | if(!__webpack_require__.o(exports, name)) {
|
49 | Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
50 | }
|
51 | };
|
52 |
|
53 |
|
54 | __webpack_require__.r = function(exports) {
|
55 | if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
56 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
57 | }
|
58 | Object.defineProperty(exports, '__esModule', { value: true });
|
59 | };
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | __webpack_require__.t = function(value, mode) {
|
67 | if(mode & 1) value = __webpack_require__(value);
|
68 | if(mode & 8) return value;
|
69 | if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
70 | var ns = Object.create(null);
|
71 | __webpack_require__.r(ns);
|
72 | Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
73 | if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
74 | return ns;
|
75 | };
|
76 |
|
77 |
|
78 | __webpack_require__.n = function(module) {
|
79 | var getter = module && module.__esModule ?
|
80 | function getDefault() { return module['default']; } :
|
81 | function getModuleExports() { return module; };
|
82 | __webpack_require__.d(getter, 'a', getter);
|
83 | return getter;
|
84 | };
|
85 |
|
86 |
|
87 | __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
88 |
|
89 |
|
90 | __webpack_require__.p = "";
|
91 |
|
92 |
|
93 |
|
94 | return __webpack_require__(__webpack_require__.s = 1);
|
95 | })
|
96 |
|
97 | ([
|
98 |
|
99 | (function(module, exports) {
|
100 |
|
101 | module.exports = __WEBPACK_EXTERNAL_MODULE__0__;
|
102 |
|
103 | }),
|
104 |
|
105 | (function(module, __webpack_exports__, __webpack_require__) {
|
106 |
|
107 | "use strict";
|
108 | __webpack_require__.r(__webpack_exports__);
|
109 |
|
110 |
|
111 | var external_katex_ = __webpack_require__(0);
|
112 | var external_katex_default = __webpack_require__.n(external_katex_);
|
113 |
|
114 |
|
115 |
|
116 | var findEndOfMath = function findEndOfMath(delimiter, text, startIndex) {
|
117 |
|
118 |
|
119 | var index = startIndex;
|
120 | var braceLevel = 0;
|
121 | var delimLength = delimiter.length;
|
122 |
|
123 | while (index < text.length) {
|
124 | var character = text[index];
|
125 |
|
126 | if (braceLevel <= 0 && text.slice(index, index + delimLength) === delimiter) {
|
127 | return index;
|
128 | } else if (character === "\\") {
|
129 | index++;
|
130 | } else if (character === "{") {
|
131 | braceLevel++;
|
132 | } else if (character === "}") {
|
133 | braceLevel--;
|
134 | }
|
135 |
|
136 | index++;
|
137 | }
|
138 |
|
139 | return -1;
|
140 | };
|
141 |
|
142 | var splitAtDelimiters = function splitAtDelimiters(startData, leftDelim, rightDelim, display) {
|
143 | var finalData = [];
|
144 |
|
145 | for (var i = 0; i < startData.length; i++) {
|
146 | if (startData[i].type === "text") {
|
147 | var text = startData[i].data;
|
148 | var lookingForLeft = true;
|
149 | var currIndex = 0;
|
150 | var nextIndex = void 0;
|
151 | nextIndex = text.indexOf(leftDelim);
|
152 |
|
153 | if (nextIndex !== -1) {
|
154 | currIndex = nextIndex;
|
155 | finalData.push({
|
156 | type: "text",
|
157 | data: text.slice(0, currIndex)
|
158 | });
|
159 | lookingForLeft = false;
|
160 | }
|
161 |
|
162 | while (true) {
|
163 | if (lookingForLeft) {
|
164 | nextIndex = text.indexOf(leftDelim, currIndex);
|
165 |
|
166 | if (nextIndex === -1) {
|
167 | break;
|
168 | }
|
169 |
|
170 | finalData.push({
|
171 | type: "text",
|
172 | data: text.slice(currIndex, nextIndex)
|
173 | });
|
174 | currIndex = nextIndex;
|
175 | } else {
|
176 | nextIndex = findEndOfMath(rightDelim, text, currIndex + leftDelim.length);
|
177 |
|
178 | if (nextIndex === -1) {
|
179 | break;
|
180 | }
|
181 |
|
182 | finalData.push({
|
183 | type: "math",
|
184 | data: text.slice(currIndex + leftDelim.length, nextIndex),
|
185 | rawData: text.slice(currIndex, nextIndex + rightDelim.length),
|
186 | display: display
|
187 | });
|
188 | currIndex = nextIndex + rightDelim.length;
|
189 | }
|
190 |
|
191 | lookingForLeft = !lookingForLeft;
|
192 | }
|
193 |
|
194 | finalData.push({
|
195 | type: "text",
|
196 | data: text.slice(currIndex)
|
197 | });
|
198 | } else {
|
199 | finalData.push(startData[i]);
|
200 | }
|
201 | }
|
202 |
|
203 | return finalData;
|
204 | };
|
205 |
|
206 | var auto_render_splitAtDelimiters = (splitAtDelimiters);
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 | var auto_render_splitWithDelimiters = function splitWithDelimiters(text, delimiters) {
|
213 | var data = [{
|
214 | type: "text",
|
215 | data: text
|
216 | }];
|
217 |
|
218 | for (var i = 0; i < delimiters.length; i++) {
|
219 | var delimiter = delimiters[i];
|
220 | data = auto_render_splitAtDelimiters(data, delimiter.left, delimiter.right, delimiter.display || false);
|
221 | }
|
222 |
|
223 | return data;
|
224 | };
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 | var auto_render_renderMathInText = function renderMathInText(text, optionsCopy) {
|
231 | var data = auto_render_splitWithDelimiters(text, optionsCopy.delimiters);
|
232 |
|
233 | if (data.length === 1 && data[0].type === 'text') {
|
234 |
|
235 |
|
236 |
|
237 | return null;
|
238 | }
|
239 |
|
240 | var fragment = document.createDocumentFragment();
|
241 |
|
242 | for (var i = 0; i < data.length; i++) {
|
243 | if (data[i].type === "text") {
|
244 | fragment.appendChild(document.createTextNode(data[i].data));
|
245 | } else {
|
246 | var span = document.createElement("span");
|
247 | var math = data[i].data;
|
248 |
|
249 |
|
250 | optionsCopy.displayMode = data[i].display;
|
251 |
|
252 | try {
|
253 | if (optionsCopy.preProcess) {
|
254 | math = optionsCopy.preProcess(math);
|
255 | }
|
256 |
|
257 | external_katex_default.a.render(math, span, optionsCopy);
|
258 | } catch (e) {
|
259 | if (!(e instanceof external_katex_default.a.ParseError)) {
|
260 | throw e;
|
261 | }
|
262 |
|
263 | optionsCopy.errorCallback("KaTeX auto-render: Failed to parse `" + data[i].data + "` with ", e);
|
264 | fragment.appendChild(document.createTextNode(data[i].rawData));
|
265 | continue;
|
266 | }
|
267 |
|
268 | fragment.appendChild(span);
|
269 | }
|
270 | }
|
271 |
|
272 | return fragment;
|
273 | };
|
274 |
|
275 | var renderElem = function renderElem(elem, optionsCopy) {
|
276 | for (var i = 0; i < elem.childNodes.length; i++) {
|
277 | var childNode = elem.childNodes[i];
|
278 |
|
279 | if (childNode.nodeType === 3) {
|
280 |
|
281 | var frag = auto_render_renderMathInText(childNode.textContent, optionsCopy);
|
282 |
|
283 | if (frag) {
|
284 | i += frag.childNodes.length - 1;
|
285 | elem.replaceChild(frag, childNode);
|
286 | }
|
287 | } else if (childNode.nodeType === 1) {
|
288 | (function () {
|
289 |
|
290 | var className = ' ' + childNode.className + ' ';
|
291 | var shouldRender = optionsCopy.ignoredTags.indexOf(childNode.nodeName.toLowerCase()) === -1 && optionsCopy.ignoredClasses.every(function (x) {
|
292 | return className.indexOf(' ' + x + ' ') === -1;
|
293 | });
|
294 |
|
295 | if (shouldRender) {
|
296 | renderElem(childNode, optionsCopy);
|
297 | }
|
298 | })();
|
299 | }
|
300 |
|
301 | }
|
302 | };
|
303 |
|
304 | var renderMathInElement = function renderMathInElement(elem, options) {
|
305 | if (!elem) {
|
306 | throw new Error("No element provided to render");
|
307 | }
|
308 |
|
309 | var optionsCopy = {};
|
310 |
|
311 | for (var option in options) {
|
312 | if (options.hasOwnProperty(option)) {
|
313 | optionsCopy[option] = options[option];
|
314 | }
|
315 | }
|
316 |
|
317 |
|
318 | optionsCopy.delimiters = optionsCopy.delimiters || [{
|
319 | left: "$$",
|
320 | right: "$$",
|
321 | display: true
|
322 | }, {
|
323 | left: "\\(",
|
324 | right: "\\)",
|
325 | display: false
|
326 | },
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 | {
|
333 | left: "\\[",
|
334 | right: "\\]",
|
335 | display: true
|
336 | }];
|
337 | optionsCopy.ignoredTags = optionsCopy.ignoredTags || ["script", "noscript", "style", "textarea", "pre", "code", "option"];
|
338 | optionsCopy.ignoredClasses = optionsCopy.ignoredClasses || [];
|
339 | optionsCopy.errorCallback = optionsCopy.errorCallback || console.error;
|
340 |
|
341 |
|
342 | optionsCopy.macros = optionsCopy.macros || {};
|
343 | renderElem(elem, optionsCopy);
|
344 | };
|
345 |
|
346 | var auto_render = __webpack_exports__["default"] = (renderMathInElement);
|
347 |
|
348 | })
|
349 | ])["default"];
|
350 | }); |
\ | No newline at end of file |