@umoteam/editor-external 9.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.
- package/build.js +3 -3
- package/edgeone.json +4 -0
- package/libs/katex/README.md +3 -3
- package/libs/katex/contrib/auto-render.js +29 -65
- package/libs/katex/contrib/auto-render.min.js +1 -1
- package/libs/katex/contrib/auto-render.mjs +34 -68
- package/libs/katex/contrib/copy-tex.js +23 -37
- package/libs/katex/contrib/copy-tex.min.js +1 -1
- package/libs/katex/contrib/copy-tex.mjs +20 -40
- package/libs/katex/contrib/mathtex-script-type.js +4 -10
- package/libs/katex/contrib/mathtex-script-type.min.js +1 -1
- package/libs/katex/contrib/mathtex-script-type.mjs +0 -3
- package/libs/katex/contrib/mhchem.js +59 -310
- package/libs/katex/contrib/mhchem.min.js +1 -1
- package/libs/katex/contrib/mhchem.mjs +62 -307
- package/libs/katex/contrib/render-a11y-string.js +17 -119
- package/libs/katex/contrib/render-a11y-string.min.js +1 -1
- package/libs/katex/contrib/render-a11y-string.mjs +55 -157
- package/libs/katex/katex-swap.css +1237 -0
- package/libs/katex/katex-swap.min.css +1 -0
- package/libs/katex/katex.css +32 -4
- package/libs/katex/katex.js +4987 -6215
- package/libs/katex/katex.min.css +1 -1
- package/libs/katex/katex.min.js +1 -1
- package/libs/katex/katex.mjs +4562 -6559
- package/libs/mermaid/mermaid.min.js +3022 -0
- package/libs/plyr/plyr.css +1 -0
- package/libs/plyr/plyr.js +8803 -0
- package/libs/plyr/plyr.min.js +2 -0
- package/libs/plyr/plyr.min.js.map +1 -0
- package/libs/plyr/plyr.min.mjs +1 -0
- package/libs/plyr/plyr.min.mjs.map +1 -0
- package/libs/plyr/plyr.mjs +8795 -0
- package/libs/plyr/plyr.polyfilled.js +9296 -0
- package/libs/plyr/plyr.polyfilled.min.js +2 -0
- package/libs/plyr/plyr.polyfilled.min.js.map +1 -0
- package/libs/plyr/plyr.polyfilled.min.mjs +1 -0
- package/libs/plyr/plyr.polyfilled.min.mjs.map +1 -0
- package/libs/plyr/plyr.polyfilled.mjs +9288 -0
- package/libs/plyr/plyr.svg +1 -0
- package/package.json +15 -16
- package/libs/imgly/background-removal-data/12086412521285f855c2921ae13d3370ab243c9a250ebe340430075780f4624b +0 -0
- package/libs/imgly/background-removal-data/26a663c5a768f39155009f52e0f66815f36983ae275eec676365f7d09ef97edd +0 -0
- package/libs/imgly/background-removal-data/378cd0ab154b324c0b1fe3136a605a8618865d4ce38824a30c938cc1e6312ce4 +0 -0
- package/libs/imgly/background-removal-data/391ce9664d3a506e4333adb82581fc2dc6fbef0354f497ab417c050cb6eba6c4 +0 -0
- package/libs/imgly/background-removal-data/417316220b16ddd1c2a4730a315206ec0405aac7b64a878bdbe514e687b07b6f +0 -0
- package/libs/imgly/background-removal-data/7b64520a3747dd5dcf6ac48f612504bb3b1e273a08b42b5a7efd614b9e4a397c +0 -0
- package/libs/imgly/background-removal-data/7b95dd2733643f999b985105afb755122ca36de12decadc7855ebfbdab6920e6 +0 -0
- package/libs/imgly/background-removal-data/8b993f75a6dc28aab79d1f216e62b59aaa6b3a15e62159bcad4a2ac197c4db0a +0 -0
- package/libs/imgly/background-removal-data/90741e8ae8b47de7666ae4163ba26087500d534973a853bbd02cea715f24b5ee +0 -0
- package/libs/imgly/background-removal-data/9f0512f9be98be0f44ad2f9ec9fe706ae626f2037aca910df6d1396a06a30d41 +0 -0
- package/libs/imgly/background-removal-data/a2a1f2d68cd58b5a6262755e434dee496fc0f27c0ba8fcbb5d57c56ffa1bb15f +0 -0
- package/libs/imgly/background-removal-data/a984abd436e7a8119dc170730260a37436ce0d0542984b71c5a1a386777ab7fd +0 -0
- package/libs/imgly/background-removal-data/af8fb2b72ffb03ed999778c4de73fd4ade196890be6e0253230b198dd11e9db0 +0 -0
- package/libs/imgly/background-removal-data/b53229786ebfbaabcfec4955c248135ba47a13972bf700116a2ff85b86507d2e +0 -0
- package/libs/imgly/background-removal-data/bbf8e366b8f11bb64e60c8532fc2ffed21535fa1cf981464ac45485972107855 +0 -0
- package/libs/imgly/background-removal-data/c1eba9d5d2ee58ba832bf98b50624ea8813f2279505643401c23674c6b326d0b +0 -0
- package/libs/imgly/background-removal-data/c9f954707cb992edf62319d9aed365b4fc9ec3f08693a020db30040c0f953198 +0 -0
- package/libs/imgly/background-removal-data/cad6b95099faeba3ea1299d717990453208cc075b53332db9123a4e2bdaf160c +0 -0
- package/libs/imgly/background-removal-data/dd4fad06953738263bc4d5f94974376467fc74081cba665cef18af8223894ed4 +0 -0
- package/libs/imgly/background-removal-data/e9445ca5ac21e04579658183cd886440f3524caafe6a8947dd20a73b34fba5b0 +0 -0
- package/libs/imgly/background-removal-data/ea46f83f60203065638f183fc8a5446dfc28a163d7ba1922fc3bc6cf40347fa2 +0 -0
- package/libs/imgly/background-removal-data/ef7fb517ae63534f48efa657702b3821fb5d59e4fd372016793edc0389341cc0 +0 -0
- package/libs/imgly/background-removal-data/f69890cf74d0a687904dd088c0aaadce598c8bc217366ebee6993eadd4d56208 +0 -0
- package/libs/imgly/background-removal-data/f6e7e01556358ed875f260bdfb22fb6f7213ac6fd4098ed72c0e7af081f0c23c +0 -0
- package/libs/imgly/background-removal-data/fa3e4102c796fb6d1dab5417c5c0b4b5d219e6b9624d045d7361a033e7db183f +0 -0
- package/libs/imgly/background-removal-data/resources.json +0 -462
- package/libs/mammoth/mammoth.browser.min.js +0 -21
package/build.js
CHANGED
|
@@ -34,12 +34,12 @@ const copyDir = (sourcePath, targetPath) => {
|
|
|
34
34
|
|
|
35
35
|
// 定义要复制的文件和目录列表
|
|
36
36
|
const files = [
|
|
37
|
-
{ from: 'imgly/background-removal-data', to: 'imgly/background-removal-data', npm: false },
|
|
38
|
-
{ from: 'mammoth', to: 'mammoth', npm: false },
|
|
39
37
|
{ from: 'flowchart', to: 'flowchart', npm: false },
|
|
40
38
|
{ from: 'plantuml', to: 'plantuml', npm: false },
|
|
41
39
|
{ from: 'katex/dist', to: 'katex' },
|
|
42
|
-
{ from:'echarts/dist',to:'echarts' }
|
|
40
|
+
{ from:'echarts/dist', to:'echarts' },
|
|
41
|
+
{ from:'plyr/dist', to:'plyr' },
|
|
42
|
+
{ from:'mermaid/dist/mermaid.min.js', to:'mermaid/mermaid.min.js' }
|
|
43
43
|
];
|
|
44
44
|
|
|
45
45
|
// 循环遍历每个要复制的文件或目录
|
package/edgeone.json
CHANGED
package/libs/katex/README.md
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
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(
|
|
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
|
-
/***/
|
|
15
|
+
/***/ 757:
|
|
16
16
|
/***/ (function(module) {
|
|
17
17
|
|
|
18
|
-
module.exports =
|
|
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__(
|
|
87
|
+
var external_katex_ = __webpack_require__(757);
|
|
90
88
|
var external_katex_default = /*#__PURE__*/__webpack_require__.n(external_katex_);
|
|
91
|
-
;//
|
|
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
|
-
}
|
|
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
|
-
;//
|
|
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;
|
|
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
|
-
|
|
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.
|
|
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
|
-
}
|
|
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
|
-
|
|
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
|
-
},
|
|
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 =
|
|
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;
|
|
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,
|
|
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
|
-
}
|
|
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;
|
|
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
|
|
136
|
-
|
|
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
|
-
|
|
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
|
-
|
|
139
|
+
_i += nSiblings;
|
|
168
140
|
}
|
|
169
141
|
} else if (childNode.nodeType === 1) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
-
|
|
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
|
-
},
|
|
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 =
|
|
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;
|
|
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
|
-
|
|
207
|
+
_renderElem(elem, optionsCopy);
|
|
242
208
|
};
|
|
243
209
|
|
|
244
210
|
export { renderMathInElement as default };
|