You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.8 KiB

  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else {
  7. var a = factory();
  8. for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
  9. }
  10. })((typeof self !== 'undefined' ? self : this), function() {
  11. return /******/ (function() { // webpackBootstrap
  12. /******/ "use strict";
  13. var __webpack_exports__ = {};
  14. ;// CONCATENATED MODULE: ./contrib/copy-tex/katex2tex.js
  15. // Set these to how you want inline and display math to be delimited.
  16. var defaultCopyDelimiters = {
  17. inline: ['$', '$'],
  18. // alternative: ['\(', '\)']
  19. display: ['$$', '$$'] // alternative: ['\[', '\]']
  20. }; // Replace .katex elements with their TeX source (<annotation> element).
  21. // Modifies fragment in-place. Useful for writing your own 'copy' handler,
  22. // as in copy-tex.js.
  23. var katexReplaceWithTex = function katexReplaceWithTex(fragment, copyDelimiters) {
  24. if (copyDelimiters === void 0) {
  25. copyDelimiters = defaultCopyDelimiters;
  26. }
  27. // Remove .katex-html blocks that are preceded by .katex-mathml blocks
  28. // (which will get replaced below).
  29. var katexHtml = fragment.querySelectorAll('.katex-mathml + .katex-html');
  30. for (var i = 0; i < katexHtml.length; i++) {
  31. var element = katexHtml[i];
  32. if (element.remove) {
  33. element.remove(null);
  34. } else {
  35. element.parentNode.removeChild(element);
  36. }
  37. } // Replace .katex-mathml elements with their annotation (TeX source)
  38. // descendant, with inline delimiters.
  39. var katexMathml = fragment.querySelectorAll('.katex-mathml');
  40. for (var _i = 0; _i < katexMathml.length; _i++) {
  41. var _element = katexMathml[_i];
  42. var texSource = _element.querySelector('annotation');
  43. if (texSource) {
  44. if (_element.replaceWith) {
  45. _element.replaceWith(texSource);
  46. } else {
  47. _element.parentNode.replaceChild(texSource, _element);
  48. }
  49. texSource.innerHTML = copyDelimiters.inline[0] + texSource.innerHTML + copyDelimiters.inline[1];
  50. }
  51. } // Switch display math to display delimiters.
  52. var displays = fragment.querySelectorAll('.katex-display annotation');
  53. for (var _i2 = 0; _i2 < displays.length; _i2++) {
  54. var _element2 = displays[_i2];
  55. _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];
  56. }
  57. return fragment;
  58. };
  59. /* harmony default export */ var katex2tex = (katexReplaceWithTex);
  60. ;// CONCATENATED MODULE: ./contrib/copy-tex/copy-tex.js
  61. // Global copy handler to modify behavior on .katex elements.
  62. document.addEventListener('copy', function (event) {
  63. var selection = window.getSelection();
  64. if (selection.isCollapsed) {
  65. return; // default action OK if selection is empty
  66. }
  67. var fragment = selection.getRangeAt(0).cloneContents();
  68. if (!fragment.querySelector('.katex-mathml')) {
  69. return; // default action OK if no .katex-mathml elements
  70. } // Preserve usual HTML copy/paste behavior.
  71. var html = [];
  72. for (var i = 0; i < fragment.childNodes.length; i++) {
  73. html.push(fragment.childNodes[i].outerHTML);
  74. }
  75. event.clipboardData.setData('text/html', html.join('')); // Rewrite plain-text version.
  76. event.clipboardData.setData('text/plain', katex2tex(fragment).textContent); // Prevent normal copy handling.
  77. event.preventDefault();
  78. });
  79. ;// CONCATENATED MODULE: ./contrib/copy-tex/copy-tex.webpack.js
  80. /**
  81. * This is the webpack entry point for KaTeX. As ECMAScript doesn't support
  82. * CSS modules natively, a separate entry point is used.
  83. */
  84. __webpack_exports__ = __webpack_exports__["default"];
  85. /******/ return __webpack_exports__;
  86. /******/ })()
  87. ;
  88. });