Mercurial > repos > public > wdown
comparison katex/contrib/copy-tex.js @ 8:4a25b534c81c javascript-experiment
Add v8 engine and include katex
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 17 Jun 2020 21:43:52 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
7:a5aa39557726 | 8:4a25b534c81c |
---|---|
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(modules) { // webpackBootstrap | |
12 /******/ // The module cache | |
13 /******/ var installedModules = {}; | |
14 /******/ | |
15 /******/ // The require function | |
16 /******/ function __webpack_require__(moduleId) { | |
17 /******/ | |
18 /******/ // Check if module is in cache | |
19 /******/ if(installedModules[moduleId]) { | |
20 /******/ return installedModules[moduleId].exports; | |
21 /******/ } | |
22 /******/ // Create a new module (and put it into the cache) | |
23 /******/ var module = installedModules[moduleId] = { | |
24 /******/ i: moduleId, | |
25 /******/ l: false, | |
26 /******/ exports: {} | |
27 /******/ }; | |
28 /******/ | |
29 /******/ // Execute the module function | |
30 /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | |
31 /******/ | |
32 /******/ // Flag the module as loaded | |
33 /******/ module.l = true; | |
34 /******/ | |
35 /******/ // Return the exports of the module | |
36 /******/ return module.exports; | |
37 /******/ } | |
38 /******/ | |
39 /******/ | |
40 /******/ // expose the modules object (__webpack_modules__) | |
41 /******/ __webpack_require__.m = modules; | |
42 /******/ | |
43 /******/ // expose the module cache | |
44 /******/ __webpack_require__.c = installedModules; | |
45 /******/ | |
46 /******/ // define getter function for harmony exports | |
47 /******/ __webpack_require__.d = function(exports, name, getter) { | |
48 /******/ if(!__webpack_require__.o(exports, name)) { | |
49 /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); | |
50 /******/ } | |
51 /******/ }; | |
52 /******/ | |
53 /******/ // define __esModule on exports | |
54 /******/ __webpack_require__.r = function(exports) { | |
55 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | |
56 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | |
57 /******/ } | |
58 /******/ Object.defineProperty(exports, '__esModule', { value: true }); | |
59 /******/ }; | |
60 /******/ | |
61 /******/ // create a fake namespace object | |
62 /******/ // mode & 1: value is a module id, require it | |
63 /******/ // mode & 2: merge all properties of value into the ns | |
64 /******/ // mode & 4: return value when already ns object | |
65 /******/ // mode & 8|1: behave like require | |
66 /******/ __webpack_require__.t = function(value, mode) { | |
67 /******/ if(mode & 1) value = __webpack_require__(value); | |
68 /******/ if(mode & 8) return value; | |
69 /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; | |
70 /******/ var ns = Object.create(null); | |
71 /******/ __webpack_require__.r(ns); | |
72 /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); | |
73 /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); | |
74 /******/ return ns; | |
75 /******/ }; | |
76 /******/ | |
77 /******/ // getDefaultExport function for compatibility with non-harmony modules | |
78 /******/ __webpack_require__.n = function(module) { | |
79 /******/ var getter = module && module.__esModule ? | |
80 /******/ function getDefault() { return module['default']; } : | |
81 /******/ function getModuleExports() { return module; }; | |
82 /******/ __webpack_require__.d(getter, 'a', getter); | |
83 /******/ return getter; | |
84 /******/ }; | |
85 /******/ | |
86 /******/ // Object.prototype.hasOwnProperty.call | |
87 /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; | |
88 /******/ | |
89 /******/ // __webpack_public_path__ | |
90 /******/ __webpack_require__.p = ""; | |
91 /******/ | |
92 /******/ | |
93 /******/ // Load entry module and return exports | |
94 /******/ return __webpack_require__(__webpack_require__.s = 1); | |
95 /******/ }) | |
96 /************************************************************************/ | |
97 /******/ ([ | |
98 /* 0 */ | |
99 /***/ (function(module, exports, __webpack_require__) { | |
100 | |
101 // extracted by mini-css-extract-plugin | |
102 | |
103 /***/ }), | |
104 /* 1 */ | |
105 /***/ (function(module, __webpack_exports__, __webpack_require__) { | |
106 | |
107 "use strict"; | |
108 __webpack_require__.r(__webpack_exports__); | |
109 | |
110 // EXTERNAL MODULE: ./contrib/copy-tex/copy-tex.css | |
111 var copy_tex = __webpack_require__(0); | |
112 | |
113 // CONCATENATED MODULE: ./contrib/copy-tex/katex2tex.js | |
114 // Set these to how you want inline and display math to be delimited. | |
115 var defaultCopyDelimiters = { | |
116 inline: ['$', '$'], | |
117 // alternative: ['\(', '\)'] | |
118 display: ['$$', '$$'] // alternative: ['\[', '\]'] | |
119 | |
120 }; // Replace .katex elements with their TeX source (<annotation> element). | |
121 // Modifies fragment in-place. Useful for writing your own 'copy' handler, | |
122 // as in copy-tex.js. | |
123 | |
124 var katexReplaceWithTex = function katexReplaceWithTex(fragment, copyDelimiters) { | |
125 if (copyDelimiters === void 0) { | |
126 copyDelimiters = defaultCopyDelimiters; | |
127 } | |
128 | |
129 // Remove .katex-html blocks that are preceded by .katex-mathml blocks | |
130 // (which will get replaced below). | |
131 var katexHtml = fragment.querySelectorAll('.katex-mathml + .katex-html'); | |
132 | |
133 for (var i = 0; i < katexHtml.length; i++) { | |
134 var element = katexHtml[i]; | |
135 | |
136 if (element.remove) { | |
137 element.remove(null); | |
138 } else { | |
139 element.parentNode.removeChild(element); | |
140 } | |
141 } // Replace .katex-mathml elements with their annotation (TeX source) | |
142 // descendant, with inline delimiters. | |
143 | |
144 | |
145 var katexMathml = fragment.querySelectorAll('.katex-mathml'); | |
146 | |
147 for (var _i = 0; _i < katexMathml.length; _i++) { | |
148 var _element = katexMathml[_i]; | |
149 | |
150 var texSource = _element.querySelector('annotation'); | |
151 | |
152 if (texSource) { | |
153 if (_element.replaceWith) { | |
154 _element.replaceWith(texSource); | |
155 } else { | |
156 _element.parentNode.replaceChild(texSource, _element); | |
157 } | |
158 | |
159 texSource.innerHTML = copyDelimiters.inline[0] + texSource.innerHTML + copyDelimiters.inline[1]; | |
160 } | |
161 } // Switch display math to display delimiters. | |
162 | |
163 | |
164 var displays = fragment.querySelectorAll('.katex-display annotation'); | |
165 | |
166 for (var _i2 = 0; _i2 < displays.length; _i2++) { | |
167 var _element2 = displays[_i2]; | |
168 _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]; | |
169 } | |
170 | |
171 return fragment; | |
172 }; | |
173 /* harmony default export */ var katex2tex = (katexReplaceWithTex); | |
174 // CONCATENATED MODULE: ./contrib/copy-tex/copy-tex.js | |
175 // Global copy handler to modify behavior on .katex elements. | |
176 | |
177 document.addEventListener('copy', function (event) { | |
178 var selection = window.getSelection(); | |
179 | |
180 if (selection.isCollapsed) { | |
181 return; // default action OK if selection is empty | |
182 } | |
183 | |
184 var fragment = selection.getRangeAt(0).cloneContents(); | |
185 | |
186 if (!fragment.querySelector('.katex-mathml')) { | |
187 return; // default action OK if no .katex-mathml elements | |
188 } // Preserve usual HTML copy/paste behavior. | |
189 | |
190 | |
191 var html = []; | |
192 | |
193 for (var i = 0; i < fragment.childNodes.length; i++) { | |
194 html.push(fragment.childNodes[i].outerHTML); | |
195 } | |
196 | |
197 event.clipboardData.setData('text/html', html.join('')); // Rewrite plain-text version. | |
198 | |
199 event.clipboardData.setData('text/plain', katex2tex(fragment).textContent); // Prevent normal copy handling. | |
200 | |
201 event.preventDefault(); | |
202 }); | |
203 // CONCATENATED MODULE: ./contrib/copy-tex/copy-tex.webpack.js | |
204 /** | |
205 * This is the webpack entry point for KaTeX. As ECMAScript doesn't support | |
206 * CSS modules natively, a separate entry point is used. | |
207 */ | |
208 | |
209 | |
210 | |
211 /***/ }) | |
212 /******/ ])["default"]; | |
213 }); |