Skip to content

Commit

Permalink
Check if HTML includes plaintext on paste
Browse files Browse the repository at this point in the history
  • Loading branch information
cskrov committed Nov 28, 2024
1 parent 6b44c7a commit 293cccd
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions frontend/src/plate/plugins/paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import { ParagraphPlugin, createPlatePlugin } from '@udecode/plate-core/react';
import { HEADING_KEYS } from '@udecode/plate-heading';
import { ListItemContentPlugin } from '@udecode/plate-list/react';

const HTML_PREFIX = '<meta charset="utf-8">';
const HTML_PREFIX_LENGTH = HTML_PREFIX.length;

export const PastePlugin = createPlatePlugin({
key: 'paste',
handlers: {
Expand All @@ -36,7 +33,8 @@ export const PastePlugin = createPlatePlugin({
const html = event.clipboardData.getData('text/html');

// HTML content from PDFs in Chrome is equal to the plain text, with <meta charset="utf-8"> prepended.
if (html.length - HTML_PREFIX_LENGTH > plainText.length) {
// Some browsers and OS will wrap the plain text in <!html><body>pain text</body></html>.
if (html.includes(plainText)) {
// Pasted HTML not from PDF.
return false;
}
Expand Down

0 comments on commit 293cccd

Please sign in to comment.