mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-07 04:08:43 +00:00
* Initial webpack config. Moving to ES6 modules. Some module cleanup. * WIP * WIP * Removing commented out code. * Removing old deps. * Removing the build script (used for testing). * Working tests. * Switching to node api over cli. * Updating per comments. Still need to fix server.js to properly run the selenium tests. * Cleaning up the config. * More cleanup. * Bringing back server.js for selenium tests. * Bringing back old dependencies. * Adding back eslint rules for webpack config. Final cleanup for webpack config. * Pointing to correct pre-existing module versions. Adding some extra logic to server.js to ensure it gets transpiled properly. * Getting make build to work again. Updating package.json with some shortcut scripts. * Resolving conflict. * Reverting back to commonjs modules. * Removing extra spaces in babelrc
25 lines
943 B
JavaScript
25 lines
943 B
JavaScript
import katexReplaceWithTex from './katex2tex';
|
|
|
|
// Global copy handler to modify behavior on .katex elements.
|
|
document.addEventListener('copy', function(event) {
|
|
const selection = window.getSelection();
|
|
if (selection.isCollapsed) {
|
|
return; // default action OK if selection is empty
|
|
}
|
|
const fragment = selection.getRangeAt(0).cloneContents();
|
|
if (!fragment.querySelector('.katex-mathml')) {
|
|
return; // default action OK if no .katex-mathml elements
|
|
}
|
|
// Preserve usual HTML copy/paste behavior.
|
|
const html = [];
|
|
for (let i = 0; i < fragment.childNodes.length; i++) {
|
|
html.push(fragment.childNodes[i].outerHTML);
|
|
}
|
|
event.clipboardData.setData('text/html', html.join(''));
|
|
// Rewrite plain-text version.
|
|
event.clipboardData.setData('text/plain',
|
|
katexReplaceWithTex(fragment).textContent);
|
|
// Prevent normal copy handling.
|
|
event.preventDefault();
|
|
});
|