MailPoet\EmailEditor\Integrations\Core\Renderer\Blocks

Text::adjustStyleAttribute()privateWC 1.0

1) We need to remove padding because we render padding on wrapping table cell
2) We also need to replace font-size to avoid clamp() because clamp() is not supported in many email clients. The font size values is automatically converted to clamp() when WP site theme is configured to use fluid layouts. Currently (WP 6.5), there is no way to disable this behavior.

Method of the class: Text{}

No Hooks.

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->adjustStyleAttribute( $block_content ): string;
$block_content(string) (required)
Block content.

Text::adjustStyleAttribute() code WC 9.8.1

private function adjustStyleAttribute( string $block_content ): string {
	$html = new \WP_HTML_Tag_Processor( $block_content );

	if ( $html->next_tag() ) {
		$element_style_value = $html->get_attribute( 'style' );
		$element_style       = isset( $element_style_value ) ? strval( $element_style_value ) : '';
		// Padding may contain value like 10px or variable like var(--spacing-10).
		$element_style = preg_replace( '/padding[^:]*:.?[0-9a-z-()]+;?/', '', $element_style );

		// Remove border styles. We apply border styles on the wrapping table cell.
		$element_style = preg_replace( '/border[^:]*:.?[0-9a-z-()#]+;?/', '', strval( $element_style ) );

		// We define the font-size on the wrapper element, but we need to keep font-size definition here
		// to prevent CSS Inliner from adding a default value and overriding the value set by user, which is on the wrapper element.
		// The value provided by WP uses clamp() function which is not supported in many email clients.
		$element_style = preg_replace( '/font-size:[^;]+;?/', 'font-size: inherit;', strval( $element_style ) );
		/** @var string $element_style */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort -- used for phpstan
		$html->set_attribute( 'style', esc_attr( $element_style ) );
		$block_content = $html->get_updated_html();
	}

	return $block_content;
}