From 838ce44c0afe80566fad89a22b7ac47a9b35a172 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 4 Aug 2021 09:45:50 +0100 Subject: [PATCH] Avoid creating public APIs for util and improve function naming for clarity As we're not sure about this fix let's not create a public API via utils. Instead revert to inlining. Also renaming the function to make it's purpose clearer. It's not a generic normalizing function so let's make it obvious this is Windows specific. --- .../components/rich-text/use-paste-handler.js | 20 ++++++++++++++++--- .../src/components/rich-text/utils.js | 14 ------------- 2 files changed, 17 insertions(+), 17 deletions(-) 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. *