Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Consider comments inside of <figcaption> as empty
  • Loading branch information
ockham committed Oct 2, 2025
commit 262995bada842f74d4546ce915f1f54c9b6a999f
31 changes: 12 additions & 19 deletions packages/block-library/src/image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,22 @@ function render_block_core_image( $attributes, $content, $block ) {
*
* @return WP_HTML_Span|false Span of input if the element is empty; otherwise false.
*/
public function block_core_image_span_of_empty_element() {
$tag_name = $this->get_tag();
$this->set_bookmark( '_wp_image_block_figcaption' );
$opener = $this->bookmarks['_wp_image_block_figcaption'];

if ( ! $this->next_tag(
array(
'tag_name' => $tag_name,
'tag_closers' => 'visit',
)
) ) {
// No matching closing tag found.
return false;
}
public function block_core_image_extract_empty_figcaption_element() {
$this->set_bookmark( 'here' );
$opener = $this->bookmarks['here'];

$this->set_bookmark( '_wp_image_block_figcaption' );
$closer = $this->bookmarks['_wp_image_block_figcaption'];
// Allow comments within the definition of “empty.”
while ( $this->next_token() && '#comment' === $this->get_token_name() ) {
continue;
}

if ( $closer->start !== $opener->start + $opener->length ) {
// Not an empty element.
if ( 'FIGCAPTION' !== $this->get_tag() || ! $this->is_tag_closer() ) {
return false;
}

$this->set_bookmark( 'here' );
$closer = $this->bookmarks['here'];

return new WP_HTML_Span( $opener->start, $closer->start + $closer->length - $opener->start );
}
};
Expand Down Expand Up @@ -98,7 +91,7 @@ public function block_core_image_span_of_empty_element() {
* we take note of its span so we can remove it later.
*/
if ( $p->next_tag( 'FIGCAPTION' ) && empty( $attributes['caption'] ) ) {
$figcaption_span = $p->block_core_image_span_of_empty_element();
$figcaption_span = $p->block_core_image_extract_empty_figcaption_element();
}

$link_destination = isset( $attributes['linkDestination'] ) ? $attributes['linkDestination'] : 'none';
Expand Down
Loading