katex 0.16.9 → 0.16.10
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/README.md +3 -3
- package/contrib/copy-tex/README.md +2 -2
- package/contrib/mathtex-script-type/README.md +5 -5
- package/contrib/mhchem/README.md +1 -1
- package/dist/README.md +3 -3
- package/dist/contrib/auto-render.js +39 -47
- package/dist/contrib/auto-render.min.js +1 -1
- package/dist/contrib/copy-tex.js +24 -27
- package/dist/contrib/copy-tex.min.js +1 -1
- package/dist/contrib/mathtex-script-type.js +3 -3
- package/dist/contrib/mathtex-script-type.min.js +1 -1
- package/dist/contrib/mhchem.js +116 -116
- package/dist/contrib/render-a11y-string.js +52 -43
- package/dist/contrib/render-a11y-string.min.js +1 -1
- package/dist/katex.css +1 -1
- package/dist/katex.js +3398 -3231
- package/dist/katex.min.css +1 -1
- package/dist/katex.min.js +1 -1
- package/dist/katex.mjs +61 -21
- package/package.json +2 -2
- package/src/MacroExpander.js +16 -5
- package/src/Parser.js +4 -3
- package/src/Settings.js +5 -1
- package/src/domTree.js +6 -5
- package/src/symbols.js +1 -1
- package/src/utils.js +23 -4
package/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.10/dist/katex.min.css" integrity="sha384-wcIxkf4k558AjM3Yz3BBFQUbk/zgIYC2R0QpeeYb+TwlBVMrlgLqwRjRtGZiK7ww" 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.10/dist/katex.min.js" integrity="sha384-hIoBPJpTUs74ddyc4bFZSM1TVlQDA60VBbJS0oA934VSz82sBx1X7kSx2ATBDIyd" 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.10/dist/contrib/auto-render.min.js" integrity="sha384-43gviWU0YVjaDtb/GhzOouOXtZMP/7XUzwPTstBeZFe/+rCMvRwr4yROQP43s0Xk" crossorigin="anonymous"
|
|
47
47
|
onload="renderMathInElement(document.body);"></script>
|
|
48
48
|
</head>
|
|
49
49
|
...
|
|
@@ -18,7 +18,7 @@ This extension isn't part of KaTeX proper, so the script should be separately
|
|
|
18
18
|
included in the page.
|
|
19
19
|
|
|
20
20
|
```html
|
|
21
|
-
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.
|
|
21
|
+
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/contrib/copy-tex.min.js" integrity="sha384-HORx6nWi8j5/mYA+y57/9/CZc5z8HnEw4WUZWy5yOn9ToKBv1l58vJaufFAn9Zzi" crossorigin="anonymous"></script>
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
(Note that, as of KaTeX 0.16.0, there is no longer a corresponding CSS file.)
|
|
@@ -35,5 +35,5 @@ statement with `require('katex/contrib/copy-tex/katex2tex.js')`.
|
|
|
35
35
|
|
|
36
36
|
ECMAScript module is also available:
|
|
37
37
|
```html
|
|
38
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.16.
|
|
38
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/contrib/copy-tex.mjs" integrity="sha384-bVEnwt0PtX+1EuJoOEcm4rgTUWvb2ILTdjHfI1gUe/r5fdqrTcQaUuRdHG2DciuQ" crossorigin="anonymous"></script>
|
|
39
39
|
```
|
|
@@ -11,7 +11,7 @@ included in the page, in addition to KaTeX.
|
|
|
11
11
|
Load the extension by adding the following line to your HTML file.
|
|
12
12
|
|
|
13
13
|
```html
|
|
14
|
-
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.
|
|
14
|
+
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/contrib/mathtex-script-type.min.js" integrity="sha384-OGHJvxKrLNowXjZcg7A8ziPZctl4h7FncefPoKSuxgVXFxeM87GCKFJvOaTeBB9q" crossorigin="anonymous"></script>
|
|
15
15
|
```
|
|
16
16
|
You can download the script and use it locally, or from a local KaTeX installation instead.
|
|
17
17
|
|
|
@@ -23,9 +23,9 @@ Then, in the body, we use a `math/tex` script to typeset the equation `x+\sqrt{1
|
|
|
23
23
|
<!DOCTYPE html>
|
|
24
24
|
<html>
|
|
25
25
|
<head>
|
|
26
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.
|
|
27
|
-
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.
|
|
28
|
-
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.
|
|
26
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/katex.min.css" integrity="sha384-wcIxkf4k558AjM3Yz3BBFQUbk/zgIYC2R0QpeeYb+TwlBVMrlgLqwRjRtGZiK7ww" crossorigin="anonymous">
|
|
27
|
+
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/katex.min.js" integrity="sha384-hIoBPJpTUs74ddyc4bFZSM1TVlQDA60VBbJS0oA934VSz82sBx1X7kSx2ATBDIyd" crossorigin="anonymous"></script>
|
|
28
|
+
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/contrib/mathtex-script-type.min.js" integrity="sha384-OGHJvxKrLNowXjZcg7A8ziPZctl4h7FncefPoKSuxgVXFxeM87GCKFJvOaTeBB9q" crossorigin="anonymous"></script>
|
|
29
29
|
</head>
|
|
30
30
|
<body>
|
|
31
31
|
<script type="math/tex">x+\sqrt{1-x^2}</script>
|
|
@@ -35,4 +35,4 @@ Then, in the body, we use a `math/tex` script to typeset the equation `x+\sqrt{1
|
|
|
35
35
|
|
|
36
36
|
ECMAScript module is also available:
|
|
37
37
|
```html
|
|
38
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.16.
|
|
38
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/contrib/mathtex-script-type.mjs" integrity="sha384-4EJvC5tvqq9XJxXvdD4JutBokuFw/dCe2AB4gZ9sRpwFFXECpL3qT43tmE0PkpVg" crossorigin="anonymous"></script>
|
package/contrib/mhchem/README.md
CHANGED
|
@@ -7,7 +7,7 @@ This extension adds to KaTeX the `\ce` and `\pu` functions from the [mhchem](htt
|
|
|
7
7
|
This extension isn't part of core KaTeX, so the script should be separately included. Write the following line into the HTML page's `<head>`. Place it *after* the line that calls `katex.js`, and if you make use of the [auto-render](https://katex.org/docs/autorender.html) extension, place it *before* the line that calls `auto-render.js`.
|
|
8
8
|
|
|
9
9
|
```html
|
|
10
|
-
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.
|
|
10
|
+
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/contrib/mhchem.min.js" integrity="sha384-ifpG+NlgMq0kvOSGqGQxW1mJKpjjMDmZdpKGq3tbvD3WPhyshCEEYClriK/wRVU0" crossorigin="anonymous"></script>
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
If you remove the `defer` attribute from this tag, then you must also remove the `defer` attribute from the `<script src="https://../katex.min.js">` tag.
|
package/dist/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.10/dist/katex.min.css" integrity="sha384-wcIxkf4k558AjM3Yz3BBFQUbk/zgIYC2R0QpeeYb+TwlBVMrlgLqwRjRtGZiK7ww" 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.10/dist/katex.min.js" integrity="sha384-hIoBPJpTUs74ddyc4bFZSM1TVlQDA60VBbJS0oA934VSz82sBx1X7kSx2ATBDIyd" 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.10/dist/contrib/auto-render.min.js" integrity="sha384-43gviWU0YVjaDtb/GhzOouOXtZMP/7XUzwPTstBeZFe/+rCMvRwr4yROQP43s0Xk" crossorigin="anonymous"
|
|
47
47
|
onload="renderMathInElement(document.body);"></script>
|
|
48
48
|
</head>
|
|
49
49
|
...
|
|
@@ -90,15 +90,15 @@ var external_katex_ = __webpack_require__(771);
|
|
|
90
90
|
var external_katex_default = /*#__PURE__*/__webpack_require__.n(external_katex_);
|
|
91
91
|
;// CONCATENATED MODULE: ./contrib/auto-render/splitAtDelimiters.js
|
|
92
92
|
/* eslint no-constant-condition:0 */
|
|
93
|
-
|
|
93
|
+
const findEndOfMath = function (delimiter, text, startIndex) {
|
|
94
94
|
// Adapted from
|
|
95
95
|
// https://github.com/Khan/perseus/blob/master/src/perseus-markdown.jsx
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
let index = startIndex;
|
|
97
|
+
let braceLevel = 0;
|
|
98
|
+
const delimLength = delimiter.length;
|
|
99
99
|
|
|
100
100
|
while (index < text.length) {
|
|
101
|
-
|
|
101
|
+
const character = text[index];
|
|
102
102
|
|
|
103
103
|
if (braceLevel <= 0 && text.slice(index, index + delimLength) === delimiter) {
|
|
104
104
|
return index;
|
|
@@ -116,18 +116,16 @@ var findEndOfMath = function findEndOfMath(delimiter, text, startIndex) {
|
|
|
116
116
|
return -1;
|
|
117
117
|
};
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
const escapeRegex = function (string) {
|
|
120
120
|
return string.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
121
121
|
};
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
const amsRegex = /^\\begin{/;
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return escapeRegex(x.left);
|
|
130
|
-
}).join("|") + ")");
|
|
125
|
+
const splitAtDelimiters = function (text, delimiters) {
|
|
126
|
+
let index;
|
|
127
|
+
const data = [];
|
|
128
|
+
const regexLeft = new RegExp("(" + delimiters.map(x => escapeRegex(x.left)).join("|") + ")");
|
|
131
129
|
|
|
132
130
|
while (true) {
|
|
133
131
|
index = text.search(regexLeft);
|
|
@@ -145,21 +143,19 @@ var splitAtDelimiters = function splitAtDelimiters(text, delimiters) {
|
|
|
145
143
|
} // ... so this always succeeds:
|
|
146
144
|
|
|
147
145
|
|
|
148
|
-
|
|
149
|
-
return text.startsWith(delim.left);
|
|
150
|
-
});
|
|
146
|
+
const i = delimiters.findIndex(delim => text.startsWith(delim.left));
|
|
151
147
|
index = findEndOfMath(delimiters[i].right, text, delimiters[i].left.length);
|
|
152
148
|
|
|
153
149
|
if (index === -1) {
|
|
154
150
|
break;
|
|
155
151
|
}
|
|
156
152
|
|
|
157
|
-
|
|
158
|
-
|
|
153
|
+
const rawData = text.slice(0, index + delimiters[i].right.length);
|
|
154
|
+
const math = amsRegex.test(rawData) ? rawData : text.slice(delimiters[i].left.length, index);
|
|
159
155
|
data.push({
|
|
160
156
|
type: "math",
|
|
161
157
|
data: math,
|
|
162
|
-
rawData
|
|
158
|
+
rawData,
|
|
163
159
|
display: delimiters[i].display
|
|
164
160
|
});
|
|
165
161
|
text = text.slice(index + delimiters[i].right.length);
|
|
@@ -184,8 +180,8 @@ var splitAtDelimiters = function splitAtDelimiters(text, delimiters) {
|
|
|
184
180
|
* API, we should copy it before mutating.
|
|
185
181
|
*/
|
|
186
182
|
|
|
187
|
-
|
|
188
|
-
|
|
183
|
+
const renderMathInText = function (text, optionsCopy) {
|
|
184
|
+
const data = auto_render_splitAtDelimiters(text, optionsCopy.delimiters);
|
|
189
185
|
|
|
190
186
|
if (data.length === 1 && data[0].type === 'text') {
|
|
191
187
|
// There is no formula in the text.
|
|
@@ -194,14 +190,14 @@ var renderMathInText = function renderMathInText(text, optionsCopy) {
|
|
|
194
190
|
return null;
|
|
195
191
|
}
|
|
196
192
|
|
|
197
|
-
|
|
193
|
+
const fragment = document.createDocumentFragment();
|
|
198
194
|
|
|
199
|
-
for (
|
|
195
|
+
for (let i = 0; i < data.length; i++) {
|
|
200
196
|
if (data[i].type === "text") {
|
|
201
197
|
fragment.appendChild(document.createTextNode(data[i].data));
|
|
202
198
|
} else {
|
|
203
|
-
|
|
204
|
-
|
|
199
|
+
const span = document.createElement("span");
|
|
200
|
+
let math = data[i].data; // Override any display mode defined in the settings with that
|
|
205
201
|
// defined by the text itself
|
|
206
202
|
|
|
207
203
|
optionsCopy.displayMode = data[i].display;
|
|
@@ -229,18 +225,18 @@ var renderMathInText = function renderMathInText(text, optionsCopy) {
|
|
|
229
225
|
return fragment;
|
|
230
226
|
};
|
|
231
227
|
|
|
232
|
-
|
|
233
|
-
for (
|
|
234
|
-
|
|
228
|
+
const renderElem = function (elem, optionsCopy) {
|
|
229
|
+
for (let i = 0; i < elem.childNodes.length; i++) {
|
|
230
|
+
const childNode = elem.childNodes[i];
|
|
235
231
|
|
|
236
232
|
if (childNode.nodeType === 3) {
|
|
237
233
|
// Text node
|
|
238
234
|
// Concatenate all sibling text nodes.
|
|
239
235
|
// Webkit browsers split very large text nodes into smaller ones,
|
|
240
236
|
// so the delimiters may be split across different nodes.
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
237
|
+
let textContentConcat = childNode.textContent;
|
|
238
|
+
let sibling = childNode.nextSibling;
|
|
239
|
+
let nSiblings = 0;
|
|
244
240
|
|
|
245
241
|
while (sibling && sibling.nodeType === Node.TEXT_NODE) {
|
|
246
242
|
textContentConcat += sibling.textContent;
|
|
@@ -248,11 +244,11 @@ var renderElem = function renderElem(elem, optionsCopy) {
|
|
|
248
244
|
nSiblings++;
|
|
249
245
|
}
|
|
250
246
|
|
|
251
|
-
|
|
247
|
+
const frag = renderMathInText(textContentConcat, optionsCopy);
|
|
252
248
|
|
|
253
249
|
if (frag) {
|
|
254
250
|
// Remove extra text nodes
|
|
255
|
-
for (
|
|
251
|
+
for (let j = 0; j < nSiblings; j++) {
|
|
256
252
|
childNode.nextSibling.remove();
|
|
257
253
|
}
|
|
258
254
|
|
|
@@ -264,30 +260,26 @@ var renderElem = function renderElem(elem, optionsCopy) {
|
|
|
264
260
|
i += nSiblings;
|
|
265
261
|
}
|
|
266
262
|
} else if (childNode.nodeType === 1) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
if (shouldRender) {
|
|
275
|
-
renderElem(childNode, optionsCopy);
|
|
276
|
-
}
|
|
277
|
-
})();
|
|
263
|
+
// Element node
|
|
264
|
+
const className = ' ' + childNode.className + ' ';
|
|
265
|
+
const shouldRender = optionsCopy.ignoredTags.indexOf(childNode.nodeName.toLowerCase()) === -1 && optionsCopy.ignoredClasses.every(x => className.indexOf(' ' + x + ' ') === -1);
|
|
266
|
+
|
|
267
|
+
if (shouldRender) {
|
|
268
|
+
renderElem(childNode, optionsCopy);
|
|
269
|
+
}
|
|
278
270
|
} // Otherwise, it's something else, and ignore it.
|
|
279
271
|
|
|
280
272
|
}
|
|
281
273
|
};
|
|
282
274
|
|
|
283
|
-
|
|
275
|
+
const renderMathInElement = function (elem, options) {
|
|
284
276
|
if (!elem) {
|
|
285
277
|
throw new Error("No element provided to render");
|
|
286
278
|
}
|
|
287
279
|
|
|
288
|
-
|
|
280
|
+
const optionsCopy = {}; // Object.assign(optionsCopy, option)
|
|
289
281
|
|
|
290
|
-
for (
|
|
282
|
+
for (const option in options) {
|
|
291
283
|
if (options.hasOwnProperty(option)) {
|
|
292
284
|
optionsCopy[option] = options[option];
|
|
293
285
|
}
|
|
@@ -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}},
|
|
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}()}));
|
package/dist/contrib/copy-tex.js
CHANGED
|
@@ -14,7 +14,7 @@ var __webpack_exports__ = {};
|
|
|
14
14
|
|
|
15
15
|
;// CONCATENATED MODULE: ./contrib/copy-tex/katex2tex.js
|
|
16
16
|
// Set these to how you want inline and display math to be delimited.
|
|
17
|
-
|
|
17
|
+
const defaultCopyDelimiters = {
|
|
18
18
|
inline: ['$', '$'],
|
|
19
19
|
// alternative: ['\(', '\)']
|
|
20
20
|
display: ['$$', '$$'] // alternative: ['\[', '\]']
|
|
@@ -30,10 +30,10 @@ function katexReplaceWithTex(fragment, copyDelimiters) {
|
|
|
30
30
|
|
|
31
31
|
// Remove .katex-html blocks that are preceded by .katex-mathml blocks
|
|
32
32
|
// (which will get replaced below).
|
|
33
|
-
|
|
33
|
+
const katexHtml = fragment.querySelectorAll('.katex-mathml + .katex-html');
|
|
34
34
|
|
|
35
|
-
for (
|
|
36
|
-
|
|
35
|
+
for (let i = 0; i < katexHtml.length; i++) {
|
|
36
|
+
const element = katexHtml[i];
|
|
37
37
|
|
|
38
38
|
if (element.remove) {
|
|
39
39
|
element.remove();
|
|
@@ -44,18 +44,17 @@ function katexReplaceWithTex(fragment, copyDelimiters) {
|
|
|
44
44
|
// descendant, with inline delimiters.
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
const katexMathml = fragment.querySelectorAll('.katex-mathml');
|
|
48
48
|
|
|
49
|
-
for (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var texSource = _element.querySelector('annotation');
|
|
49
|
+
for (let i = 0; i < katexMathml.length; i++) {
|
|
50
|
+
const element = katexMathml[i];
|
|
51
|
+
const texSource = element.querySelector('annotation');
|
|
53
52
|
|
|
54
53
|
if (texSource) {
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
} else if (
|
|
58
|
-
|
|
54
|
+
if (element.replaceWith) {
|
|
55
|
+
element.replaceWith(texSource);
|
|
56
|
+
} else if (element.parentNode) {
|
|
57
|
+
element.parentNode.replaceChild(texSource, element);
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
texSource.innerHTML = copyDelimiters.inline[0] + texSource.innerHTML + copyDelimiters.inline[1];
|
|
@@ -63,11 +62,11 @@ function katexReplaceWithTex(fragment, copyDelimiters) {
|
|
|
63
62
|
} // Switch display math to display delimiters.
|
|
64
63
|
|
|
65
64
|
|
|
66
|
-
|
|
65
|
+
const displays = fragment.querySelectorAll('.katex-display annotation');
|
|
67
66
|
|
|
68
|
-
for (
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
for (let i = 0; i < displays.length; i++) {
|
|
68
|
+
const element = displays[i];
|
|
69
|
+
element.innerHTML = copyDelimiters.display[0] + element.innerHTML.substr(copyDelimiters.inline[0].length, element.innerHTML.length - copyDelimiters.inline[0].length - copyDelimiters.inline[1].length) + copyDelimiters.display[1];
|
|
71
70
|
}
|
|
72
71
|
|
|
73
72
|
return fragment;
|
|
@@ -79,43 +78,41 @@ function katexReplaceWithTex(fragment, copyDelimiters) {
|
|
|
79
78
|
function closestKatex(node) {
|
|
80
79
|
// If node is a Text Node, for example, go up to containing Element,
|
|
81
80
|
// where we can apply the `closest` method.
|
|
82
|
-
|
|
81
|
+
const element = node instanceof Element ? node : node.parentElement;
|
|
83
82
|
return element && element.closest('.katex');
|
|
84
83
|
} // Global copy handler to modify behavior on/within .katex elements.
|
|
85
84
|
|
|
86
85
|
|
|
87
86
|
document.addEventListener('copy', function (event) {
|
|
88
|
-
|
|
87
|
+
const selection = window.getSelection();
|
|
89
88
|
|
|
90
89
|
if (selection.isCollapsed || !event.clipboardData) {
|
|
91
90
|
return; // default action OK if selection is empty or unchangeable
|
|
92
91
|
}
|
|
93
92
|
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
const clipboardData = event.clipboardData;
|
|
94
|
+
const range = selection.getRangeAt(0); // When start point is within a formula, expand to entire formula.
|
|
96
95
|
|
|
97
|
-
|
|
96
|
+
const startKatex = closestKatex(range.startContainer);
|
|
98
97
|
|
|
99
98
|
if (startKatex) {
|
|
100
99
|
range.setStartBefore(startKatex);
|
|
101
100
|
} // Similarly, when end point is within a formula, expand to entire formula.
|
|
102
101
|
|
|
103
102
|
|
|
104
|
-
|
|
103
|
+
const endKatex = closestKatex(range.endContainer);
|
|
105
104
|
|
|
106
105
|
if (endKatex) {
|
|
107
106
|
range.setEndAfter(endKatex);
|
|
108
107
|
}
|
|
109
108
|
|
|
110
|
-
|
|
109
|
+
const fragment = range.cloneContents();
|
|
111
110
|
|
|
112
111
|
if (!fragment.querySelector('.katex-mathml')) {
|
|
113
112
|
return; // default action OK if no .katex-mathml elements
|
|
114
113
|
}
|
|
115
114
|
|
|
116
|
-
|
|
117
|
-
return el instanceof Text ? el.textContent : el.outerHTML;
|
|
118
|
-
}).join(''); // Preserve usual HTML copy/paste behavior.
|
|
115
|
+
const htmlContents = Array.prototype.map.call(fragment.childNodes, el => el instanceof Text ? el.textContent : el.outerHTML).join(''); // Preserve usual HTML copy/paste behavior.
|
|
119
116
|
|
|
120
117
|
clipboardData.setData('text/html', htmlContents); // Rewrite plain-text version.
|
|
121
118
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var
|
|
1
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}("undefined"!=typeof self?self:this,(function(){return function(){"use strict";var e={};const t={inline:["$","$"],display:["$$","$$"]};var n=function(e,n){void 0===n&&(n=t);const o=e.querySelectorAll(".katex-mathml + .katex-html");for(let e=0;e<o.length;e++){const t=o[e];t.remove?t.remove():t.parentNode&&t.parentNode.removeChild(t)}const r=e.querySelectorAll(".katex-mathml");for(let e=0;e<r.length;e++){const t=r[e],o=t.querySelector("annotation");o&&(t.replaceWith?t.replaceWith(o):t.parentNode&&t.parentNode.replaceChild(o,t),o.innerHTML=n.inline[0]+o.innerHTML+n.inline[1])}const l=e.querySelectorAll(".katex-display annotation");for(let e=0;e<l.length;e++){const t=l[e];t.innerHTML=n.display[0]+t.innerHTML.substr(n.inline[0].length,t.innerHTML.length-n.inline[0].length-n.inline[1].length)+n.display[1]}return e};function o(e){const t=e instanceof Element?e:e.parentElement;return t&&t.closest(".katex")}return document.addEventListener("copy",(function(e){const t=window.getSelection();if(t.isCollapsed||!e.clipboardData)return;const r=e.clipboardData,l=t.getRangeAt(0),i=o(l.startContainer);i&&l.setStartBefore(i);const a=o(l.endContainer);a&&l.setEndAfter(a);const s=l.cloneContents();if(!s.querySelector(".katex-mathml"))return;const c=Array.prototype.map.call(s.childNodes,(e=>e instanceof Text?e.textContent:e.outerHTML)).join("");r.setData("text/html",c),r.setData("text/plain",n(s).textContent),e.preventDefault()})),e=e.default}()}));
|
|
@@ -82,15 +82,15 @@ var __webpack_exports__ = {};
|
|
|
82
82
|
/* harmony import */ var katex__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(771);
|
|
83
83
|
/* harmony import */ var katex__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(katex__WEBPACK_IMPORTED_MODULE_0__);
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
let scripts = document.body.getElementsByTagName("script");
|
|
86
86
|
scripts = Array.prototype.slice.call(scripts);
|
|
87
87
|
scripts.forEach(function (script) {
|
|
88
88
|
if (!script.type || !script.type.match(/math\/tex/i)) {
|
|
89
89
|
return -1;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
const display = script.type.match(/mode\s*=\s*display(;|\s|\n|$)/) != null;
|
|
93
|
+
const katexElement = document.createElement(display ? "div" : "span");
|
|
94
94
|
katexElement.setAttribute("class", display ? "equation" : "inline-equation");
|
|
95
95
|
|
|
96
96
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("katex"));else if("function"==typeof define&&define.amd)define(["katex"],t);else{var
|
|
1
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("katex"));else if("function"==typeof define&&define.amd)define(["katex"],t);else{var n="object"==typeof exports?t(require("katex")):t(e.katex);for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}("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(){var e=r(771),t=r.n(e);let n=document.body.getElementsByTagName("script");n=Array.prototype.slice.call(n),n.forEach((function(e){if(!e.type||!e.type.match(/math\/tex/i))return-1;const n=null!=e.type.match(/mode\s*=\s*display(;|\s|\n|$)/),r=document.createElement(n?"div":"span");r.setAttribute("class",n?"equation":"inline-equation");try{t().render(e.text,r,{displayMode:n})}catch(t){r.textContent=e.text}e.parentNode.replaceChild(r,e)}))}(),o=o.default}()}));
|