find_element( $tag_name );
return $element ? $dom_helper->get_element_inner_html( $element ) : $block_content;
}
/**
* Add a spacer around the block for vertical spacing (margin-top).
*
* Horizontal root padding is applied uniformly by Content_Renderer::render_block()
* so that all blocks — including those using render_email_callback without
* Abstract_Block_Renderer — receive consistent padding.
*
* @param string $content The block content.
* @param array $email_attrs The email attributes.
* @return string
*/
protected function add_spacer( $content, $email_attrs ): string {
// Filter out empty margin-top values to prevent malformed CSS output.
$margin_top_attrs = array_intersect_key( $email_attrs, array_flip( array( 'margin-top' ) ) );
if ( isset( $margin_top_attrs['margin-top'] ) && '' === trim( $margin_top_attrs['margin-top'] ) ) {
$margin_top_attrs = array();
}
$gap_style = WP_Style_Engine::compile_css( $margin_top_attrs, '' ) ?? '';
$table_attrs = array(
'align' => $this->current_rendering_context ? $this->current_rendering_context->get_default_text_align() : 'left',
'width' => '100%',
'style' => $gap_style,
);
$div_content = sprintf(
'
%2$s
',
esc_attr( $gap_style ),
$content
);
return Table_Wrapper_Helper::render_outlook_table_wrapper( $div_content, $table_attrs );
}
/**
* Add a spacer around the block with rendering context.
*
* @param string $content The block content.
* @param array $email_attrs The email attributes.
* @param Rendering_Context|null $rendering_context Rendering context.
* @return string
*/
protected function add_spacer_with_context( $content, $email_attrs, ?Rendering_Context $rendering_context = null ): string {
$previous_context = $this->current_rendering_context;
$this->current_rendering_context = $rendering_context;
try {
return $this->add_spacer( $content, $email_attrs );
} finally {
$this->current_rendering_context = $previous_context;
}
}
/**
* Render the block.
*
* @param string $block_content The block content.
* @param array $parsed_block The parsed block.
* @param Rendering_Context $rendering_context The rendering context.
* @return string
*/
public function render( string $block_content, array $parsed_block, Rendering_Context $rendering_context ): string {
return $this->add_spacer_with_context(
$this->render_content( $block_content, $parsed_block, $rendering_context ),
$parsed_block['email_attrs'] ?? array(),
$rendering_context
);
}
/**
* Render the block content.
*
* @param string $block_content The block content.
* @param array $parsed_block The parsed block.
* @param Rendering_Context $rendering_context The rendering context.
* @return string
*/
abstract protected function render_content( string $block_content, array $parsed_block, Rendering_Context $rendering_context ): string;
}