Skip to content

Commit

Permalink
Avoid creating public APIs for util and improve function naming for c…
Browse files Browse the repository at this point in the history
…larity

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.
  • Loading branch information
getdave committed Aug 4, 2021
1 parent d4657d8 commit 838ce44
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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( '.*<!--StartFragment-->', 's' );
const endReg = new RegExp( '<!--EndFragment-->.*', 's' );

return html.replace( startReg, '' ).replace( endReg, '' );
}
14 changes: 0 additions & 14 deletions packages/block-editor/src/components/rich-text/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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( '.*<!--StartFragment-->', 's' );
const endReg = new RegExp( '<!--EndFragment-->.*', 's' );

return html.replace( startReg, '' ).replace( endReg, '' );
}

/**
* Get the multiline tag based on the multiline prop.
*
Expand Down

0 comments on commit 838ce44

Please sign in to comment.