react-code-dataset / wp-calypso /client /lib /formatting /unescape-and-format-spaces.js
Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
import { decodeEntities } from './decode-entities';
const nbsp = String.fromCharCode( 160 );
/**
* Unescape HTML entities, then replace spaces with  .
*
* This helper is used to transform tag names for rendering by React. We need
* to decode HTML entities in tag names because the REST API returns them
* already escaped, and React will escape them again. Also transform spaces to
* non-breaking spaces so that tags like 'a b' will display correctly (not
* using ' ' for this because again, React will escape whatever we pass
* in).
* @param {string} str String to unescape in preparation for React rendering
* @returns {string} Transformed string
*/
export function unescapeAndFormatSpaces( str ) {
return decodeEntities( str ).replace( / /g, nbsp );
}