PluginProbe
Gutenberg / trunk
Gutenberg vtrunk
24.1.0 24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 All 404 releases
← All changes | build/scripts/block-library/table-of-contents.php +17 -4 23.7.0 → trunk View file →
@@ -13,9 +13,9 @@
13 13 /**
14 14 * Adds an aria-label to the table of contents block content.
15 15 *
16 16 * @param array $attributes Attributes of the block being rendered.
17 - * @param string $content Content of the block being rendered.
17 + * @param string $content Content of the block being rendered.
18 18 *
19 19 * @return string The content of the block being rendered.
20 20 */
21 21 function gutenberg_block_core_table_of_contents_add_aria_label( $attributes, $content ) {
@@ -362,16 +362,29 @@
362 362
363 363 /**
364 364 * Renders the table of contents block from current post headings.
365 365 *
366 - * @param array $attributes Attributes of the block being rendered.
367 - * @param string $content Content of the block being rendered.
366 + * @param array $attributes Attributes of the block being rendered.
367 + * @param string $content Content of the block being rendered.
368 + * @param WP_Block|null $block Block instance.
368 369 *
369 370 * @return string The content of the block being rendered.
370 371 */
371 -function gutenberg_block_core_table_of_contents_render( $attributes, $content ) {
372 +function gutenberg_block_core_table_of_contents_render( $attributes, $content, $block = null ) {
372 373 global $wp_current_filter;
373 374
375 + // Preserve legacy saved markup for old posts that have not been edited and migrated yet.
376 + $legacy_content = $content;
377 + if ( '' === trim( $legacy_content ) && ! empty( $block->parsed_block['innerHTML'] ) ) {
378 + $legacy_content = $block->parsed_block['innerHTML'];
379 + }
380 +
381 + // Once a post is edited and saved, the block migrates to dynamic rendering.
382 + if ( '' !== trim( $legacy_content ) ) {
383 + return gutenberg_block_core_table_of_contents_add_aria_label( $attributes, $legacy_content );
384 + }
385 +
386 + // Outside post content rendering, there is no reliable current post to scan.
374 387 if ( ! is_array( $wp_current_filter ) || ! in_array( 'the_content', $wp_current_filter, true ) ) {
375 388 return gutenberg_block_core_table_of_contents_add_aria_label( $attributes, $content );
376 389 }
377 390