www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

copy-tex.js (3869B)


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