How to use @wordpress/escape-html - 8 common examples

To help you get started, we’ve selected a few @wordpress/escape-html examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github woocommerce / woocommerce-gutenberg-products-block / assets / js / blocks / reviews / edit-utils.js View on Github external
label={ __( 'Product rating', 'woo-gutenberg-products-block' ) }
				checked={ attributes.showReviewRating }
				onChange={ () =>
					setAttributes( {
						showReviewRating: ! attributes.showReviewRating,
					} )
				}
			/>
			{ attributes.showReviewRating && ! REVIEW_RATINGS_ENABLED && (
				
					
						{ sprintf(
							escapeHTML(
								/* translators: A notice that links to WooCommerce settings. */
								__(
									'Product rating is disabled in your %sstore settings%s.',
									'woo-gutenberg-products-block'
								)
							),
							`<a href="${ getAdminLink(
								'admin.php?page=wc-settings&amp;tab=products'
							) }">`,
							'</a>'
						) }
					
				
			) }
github WordPress / gutenberg / packages / element / src / serialize.js View on Github external
// Only write boolean value as attribute if meaningful.
		if ( typeof value === 'boolean' && ! isMeaningfulAttribute ) {
			continue;
		}

		result += ' ' + attribute;

		// Boolean attributes should write attribute name, but without value.
		// Mere presence of attribute name is effective truthiness.
		if ( isBooleanAttribute ) {
			continue;
		}

		if ( typeof value === 'string' ) {
			value = escapeAttribute( value );
		}

		result += '="' + value + '"';
	}

	return result;
}
github WordPress / gutenberg / packages / element / src / serialize.js View on Github external
export function renderAttributes( props ) {
	let result = '';

	for ( const key in props ) {
		const attribute = getNormalAttributeName( key );
		if ( ! isValidAttributeName( attribute ) ) {
			continue;
		}

		let value = getNormalAttributeValue( key, props[ key ] );

		// If value is not of serializeable type, skip.
		if ( ! ATTRIBUTES_TYPES.has( typeof value ) ) {
			continue;
		}

		// Don't render internal attribute names.
		if ( isInternalAttribute( key ) ) {
			continue;
		}

		const isBooleanAttribute = BOOLEAN_ATTRIBUTES.has( attribute );
github WordPress / gutenberg / packages / element / src / serialize.js View on Github external
export function renderElement( element, context, legacyContext = {} ) {
	if ( null === element || undefined === element || false === element ) {
		return '';
	}

	if ( Array.isArray( element ) ) {
		return renderChildren( element, context, legacyContext );
	}

	switch ( typeof element ) {
		case 'string':
			return escapeHTML( element );

		case 'number':
			return element.toString();
	}

	const { type, props } = element;

	switch ( type ) {
		case StrictMode:
		case Fragment:
			return renderChildren( props.children, context, legacyContext );

		case RawHTML:
			const { children, ...wrapperProps } = props;

			return renderNativeComponent(
github Automattic / vip-go-mu-plugins-built / jetpack / extensions / blocks / slideshow / swiper-callbacks.js View on Github external
function announceCurrentSlide( swiper ) {
	const currentSlide = swiper.slides[ swiper.activeIndex ];
	if ( ! currentSlide ) {
		return;
	}
	const figcaption = currentSlide.getElementsByTagName( 'FIGCAPTION' )[ 0 ];
	const img = currentSlide.getElementsByTagName( 'IMG' )[ 0 ];
	if ( swiper.a11y.liveRegion ) {
		swiper.a11y.liveRegion[ 0 ].innerHTML = figcaption
			? figcaption.innerHTML
			: escapeHTML( img.alt );
	}
}
github WordPress / gutenberg / packages / rich-text / src / to-html-string.js View on Github external
return children.map( ( child ) => {
		return child.text === undefined ? createElementHTML( child ) : escapeHTML( child.text );
	} ).join( '' );
}
github WordPress / gutenberg / packages / rich-text / src / to-html-string.js View on Github external
function createElementHTML( { type, attributes, object, children } ) {
	let attributeString = '';

	for ( const key in attributes ) {
		if ( ! isValidAttributeName( key ) ) {
			continue;
		}

		attributeString += ` ${ key }="${ escapeAttribute( attributes[ key ] ) }"`;
	}

	if ( object ) {
		return `&lt;${ type }${ attributeString }&gt;`;
	}

	return `&lt;${ type }${ attributeString }&gt;${ createChildrenHTML( children ) }`;
}
github WordPress / gutenberg / packages / rich-text / src / to-html-string.js View on Github external
function createElementHTML( { type, attributes, object, children } ) {
	let attributeString = '';

	for ( const key in attributes ) {
		if ( ! isValidAttributeName( key ) ) {
			continue;
		}

		attributeString += ` ${ key }="${ escapeAttribute( attributes[ key ] ) }"`;
	}

	if ( object ) {
		return `&lt;${ type }${ attributeString }&gt;`;
	}

	return `&lt;${ type }${ attributeString }&gt;${ createChildrenHTML( children ) }`;
}

@wordpress/escape-html

Escape HTML utils.

GPL-2.0-or-later
Latest version published 3 days ago

Package Health Score

98 / 100
Full package analysis