katex 0.16.34 → 0.16.35
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.mjs +11982 -11900
- package/dist/contrib/copy-tex.mjs +70 -72
- package/dist/contrib/mathtex-script-type.mjs +11792 -11726
- package/dist/contrib/mhchem.mjs +8791 -9056
- package/dist/contrib/render-a11y-string.mjs +12441 -12307
- package/dist/katex-swap.css +1 -1
- package/dist/katex-swap.min.css +1 -1
- package/dist/katex.css +1 -1
- package/dist/katex.js +1 -1
- package/dist/katex.min.css +1 -1
- package/dist/katex.min.js +1 -1
- package/dist/katex.mjs +11793 -11727
- package/package.json +2 -1
|
@@ -1,87 +1,85 @@
|
|
|
1
1
|
// Set these to how you want inline and display math to be delimited.
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var defaultCopyDelimiters = {
|
|
3
|
+
inline: ['$', '$'],
|
|
4
|
+
// alternative: ['\(', '\)']
|
|
5
|
+
display: ['$$', '$$'] // alternative: ['\[', '\]']
|
|
5
6
|
};
|
|
6
7
|
// Replace .katex elements with their TeX source (<annotation> element).
|
|
7
8
|
// Modifies fragment in-place. Useful for writing your own 'copy' handler,
|
|
8
9
|
// as in copy-tex.js.
|
|
9
|
-
function katexReplaceWithTex(fragment, copyDelimiters
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
function katexReplaceWithTex(fragment, copyDelimiters) {
|
|
11
|
+
if (copyDelimiters === void 0) {
|
|
12
|
+
copyDelimiters = defaultCopyDelimiters;
|
|
13
|
+
}
|
|
14
|
+
// Remove .katex-html blocks that are preceded by .katex-mathml blocks
|
|
15
|
+
// (which will get replaced below).
|
|
16
|
+
var katexHtml = fragment.querySelectorAll('.katex-mathml + .katex-html');
|
|
17
|
+
for (var i = 0; i < katexHtml.length; i++) {
|
|
18
|
+
var element = katexHtml[i];
|
|
19
|
+
if (element.remove) {
|
|
20
|
+
element.remove();
|
|
21
|
+
} else if (element.parentNode) {
|
|
22
|
+
element.parentNode.removeChild(element);
|
|
21
23
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
texSource.innerHTML + copyDelimiters.inline[1];
|
|
37
|
-
}
|
|
24
|
+
}
|
|
25
|
+
// Replace .katex-mathml elements with their annotation (TeX source)
|
|
26
|
+
// descendant, with inline delimiters.
|
|
27
|
+
var katexMathml = fragment.querySelectorAll('.katex-mathml');
|
|
28
|
+
for (var _i = 0; _i < katexMathml.length; _i++) {
|
|
29
|
+
var _element = katexMathml[_i];
|
|
30
|
+
var texSource = _element.querySelector('annotation');
|
|
31
|
+
if (texSource) {
|
|
32
|
+
if (_element.replaceWith) {
|
|
33
|
+
_element.replaceWith(texSource);
|
|
34
|
+
} else if (_element.parentNode) {
|
|
35
|
+
_element.parentNode.replaceChild(texSource, _element);
|
|
36
|
+
}
|
|
37
|
+
texSource.innerHTML = copyDelimiters.inline[0] + texSource.innerHTML + copyDelimiters.inline[1];
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
return fragment;
|
|
39
|
+
}
|
|
40
|
+
// Switch display math to display delimiters.
|
|
41
|
+
var displays = fragment.querySelectorAll('.katex-display annotation');
|
|
42
|
+
for (var _i2 = 0; _i2 < displays.length; _i2++) {
|
|
43
|
+
var _element2 = displays[_i2];
|
|
44
|
+
_element2.innerHTML = copyDelimiters.display[0] + _element2.innerHTML.substr(copyDelimiters.inline[0].length, _element2.innerHTML.length - copyDelimiters.inline[0].length - copyDelimiters.inline[1].length) + copyDelimiters.display[1];
|
|
45
|
+
}
|
|
46
|
+
return fragment;
|
|
49
47
|
}
|
|
50
48
|
|
|
51
49
|
// Return <div class="katex"> element containing node, or null if not found.
|
|
52
50
|
function closestKatex(node) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
// If node is a Text Node, for example, go up to containing Element,
|
|
52
|
+
// where we can apply the `closest` method.
|
|
53
|
+
var element = node instanceof Element ? node : node.parentElement;
|
|
54
|
+
return element && element.closest('.katex');
|
|
57
55
|
}
|
|
58
56
|
// Global copy handler to modify behavior on/within .katex elements.
|
|
59
57
|
document.addEventListener('copy', function (event) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
58
|
+
var selection = window.getSelection();
|
|
59
|
+
if (!selection || selection.isCollapsed || !event.clipboardData) {
|
|
60
|
+
return; // default action OK if selection is empty or unchangeable
|
|
61
|
+
}
|
|
62
|
+
var clipboardData = event.clipboardData;
|
|
63
|
+
var range = selection.getRangeAt(0);
|
|
64
|
+
// When start point is within a formula, expand to entire formula.
|
|
65
|
+
var startKatex = closestKatex(range.startContainer);
|
|
66
|
+
if (startKatex) {
|
|
67
|
+
range.setStartBefore(startKatex);
|
|
68
|
+
}
|
|
69
|
+
// Similarly, when end point is within a formula, expand to entire formula.
|
|
70
|
+
var endKatex = closestKatex(range.endContainer);
|
|
71
|
+
if (endKatex) {
|
|
72
|
+
range.setEndAfter(endKatex);
|
|
73
|
+
}
|
|
74
|
+
var fragment = range.cloneContents();
|
|
75
|
+
if (!fragment.querySelector('.katex-mathml')) {
|
|
76
|
+
return; // default action OK if no .katex-mathml elements
|
|
77
|
+
}
|
|
78
|
+
var htmlContents = Array.prototype.map.call(fragment.childNodes, el => el instanceof Text ? el.textContent : el.outerHTML).join('');
|
|
79
|
+
// Preserve usual HTML copy/paste behavior.
|
|
80
|
+
clipboardData.setData('text/html', htmlContents);
|
|
81
|
+
// Rewrite plain-text version.
|
|
82
|
+
clipboardData.setData('text/plain', katexReplaceWithTex(fragment).textContent);
|
|
83
|
+
// Prevent normal copy handling.
|
|
84
|
+
event.preventDefault();
|
|
87
85
|
});
|