getAttribute( 'src' ) ) {
return $html;
}
$attributes = $block['attrs'] ?? [];
$html = ! $html ? '
' : $html;
$dom = dom( $html );
$styles = css_array_to_string( add_block_support_color( [], $attributes ) );
$svg = '';
$svg_dom = dom( $svg );
$svg_element = get_dom_element( 'svg', $svg_dom );
$result = $dom->importNode( $svg_element, true );
$figure = get_dom_element( 'figure', $dom );
if ( ! $figure ) {
return $html;
}
$img = get_dom_element( 'img', $figure );
if ( $img ) {
$figure->removeChild( $img );
}
$figure->appendChild( $result );
$classes = explode( ' ', $figure->getAttribute( 'class' ) );
if ( ! in_array( 'is-placeholder', $classes, true ) ) {
$classes[] = 'is-placeholder';
}
if ( $block['align'] ?? null ) {
$classes[] = 'align' . $block['align'];
}
$figure->setAttribute( 'class', implode( ' ', $classes ) );
$styles = [
'width' => $block['width'] ?? null,
'height' => $block['height'] ?? null,
'margin-top' => $block['style']['spacing']['margin']['top'] ?? null,
'margin-right' => $block['style']['spacing']['margin']['right'] ?? null,
'margin-bottom' => $block['style']['spacing']['margin']['bottom'] ?? 'var(--wp--preset--spacing--sm)',
// TODO: Get from theme.json.
'margin-left' => $block['style']['spacing']['margin']['left'] ?? null,
'border-top-left-radius' => $block['style']['border']['radius']['topLeft'] ?? null,
'border-top-right-radius' => $block['style']['border']['radius']['topRight'] ?? null,
'border-bottom-left-radius' => $block['style']['border']['radius']['bottomLeft'] ?? null,
'border-bottom-right-radius' => $block['style']['border']['radius']['bottomRight'] ?? null,
];
$figure->setAttribute(
'style',
css_array_to_string(
\array_merge(
css_string_to_array( $figure->getAttribute( 'style' ) ),
$styles,
)
)
);
return $dom->saveHTML();
}