diff --git a/packages/block-editor/src/components/rich-text/use-paste-handler.js b/packages/block-editor/src/components/rich-text/use-paste-handler.js index 511a62300e36c0..c12e84720649f8 100644 --- a/packages/block-editor/src/components/rich-text/use-paste-handler.js +++ b/packages/block-editor/src/components/rich-text/use-paste-handler.js @@ -69,6 +69,9 @@ export function usePasteHandler( props ) { } } + // Remove Windows-specific metadata appended within copied HTML text. + html = removeWindowsFragments( html ); + event.preventDefault(); // Allows us to ask for this information when we get a report. @@ -222,3 +225,17 @@ export function usePasteHandler( props ) { }; }, [] ); } + +/** + * Normalizes a given string of HTML to remove the Windows specific "Fragment" comments + * and any preceeding and trailing whitespace. + * + * @param {string} html the html to be normalized + * @return {string} the normalized html + */ +function removeWindowsFragments( html ) { + const startReg = /.*/s; + const endReg = /.*/s; + + return html.replace( startReg, '' ).replace( endReg, '' ); +}