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 71339cc64c342..4b685924e4865 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 @@ -18,7 +18,7 @@ import { isURL } from '@wordpress/url'; * Internal dependencies */ import { filePasteHandler } from './file-paste-handler'; -import { addActiveFormats, isShortcode, normalizeCopiedHtml } from './utils'; +import { addActiveFormats, isShortcode } from './utils'; import { splitValue } from './split-value'; export function usePasteHandler( props ) { @@ -69,8 +69,8 @@ export function usePasteHandler( props ) { } } - // Remove OS-specific metadata appended within copied HTML text. - html = normalizeCopiedHtml( html ); + // Remove Windows-specific metadata appended within copied HTML text. + html = removeWindowsFragments( html ); event.preventDefault(); @@ -225,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 = new RegExp( '.*', 's' ); + const endReg = new RegExp( '.*', 's' ); + + return html.replace( startReg, '' ).replace( endReg, '' ); +} diff --git a/packages/block-editor/src/components/rich-text/utils.js b/packages/block-editor/src/components/rich-text/utils.js index d6fb8e00c34c2..f1385eda82e26 100644 --- a/packages/block-editor/src/components/rich-text/utils.js +++ b/packages/block-editor/src/components/rich-text/utils.js @@ -17,20 +17,6 @@ export function addActiveFormats( value, activeFormats ) { } } -/** - * 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 - */ -export function normalizeCopiedHtml( html ) { - const startReg = new RegExp( '.*', 's' ); - const endReg = new RegExp( '.*', 's' ); - - return html.replace( startReg, '' ).replace( endReg, '' ); -} - /** * Get the multiline tag based on the multiline prop. *