Automattic\WooCommerce\EmailEditor\Engine\Renderer\ContentRenderer

Content_Renderer::preprocess_parsed_blockspublicWC 1.0

Preprocess parsed blocks.

Called for both template blocks and post-content user blocks. The Spacing_Preprocessor handles root padding distribution: container blocks (groups wrapping post-content) are transparent, delegating padding to their children so user blocks get individual padding.

Method of the class: Content_Renderer{}

No Hooks.

Returns

Array.

Usage

$Content_Renderer = new Content_Renderer();
$Content_Renderer->preprocess_parsed_blocks( $parsed_blocks ): array;
$parsed_blocks(array) (required)
Parsed blocks.

Content_Renderer::preprocess_parsed_blocks() code WC 10.7.0

public function preprocess_parsed_blocks( array $parsed_blocks ): array {
	$styles = $this->theme_controller->get_styles();
	$layout = $this->theme_controller->get_layout_settings();

	// Pass the CSS variables map so preprocessors can resolve preset
	// references (e.g. var:preset|spacing|20) in block attributes.
	$styles['__variables_map'] = $this->theme_controller->get_variables_values_map();

	// Second pass (user blocks inside post-content): if root padding was
	// applied to a container above post-content in the first pass (indicated
	// by post_content_width < contentSize), remove root padding from styles
	// to prevent double application. If the template delegates root padding
	// (post_content_width == contentSize), keep it for user blocks.
	if ( null !== $this->post_content_width ) {
		$post_content_num = (float) str_replace( 'px', '', $this->post_content_width );
		$content_size_num = (float) str_replace( 'px', '', $layout['contentSize'] );
		// Use epsilon tolerance for floating-point comparison since width
		// calculations involve round() and division that may produce imprecision.
		if ( $post_content_num < $content_size_num - 0.01 ) {
			unset( $styles['spacing']['padding']['left'], $styles['spacing']['padding']['right'] );
		}

		// Pass container padding from the first pass so the
		// Spacing_Preprocessor can distribute it to user blocks.
		if ( ! empty( $this->container_padding ) ) {
			$styles['__container_padding'] = $this->container_padding;
		}
	}

	$result = $this->process_manager->preprocess( $parsed_blocks, $layout, $styles );

	// After the first pass: find the post-content block's width and container padding.
	if ( null === $this->post_content_width ) {
		$this->post_content_width = $this->find_post_content_width( $result );
		$this->container_padding  = $this->find_container_padding( $result );
	}

	return $result;
}