From 02a4039d59ec85634bf959e7fe08dbc3f50994ae Mon Sep 17 00:00:00 2001 From: Laurel Fulford Date: Wed, 13 May 2026 13:24:57 -0700 Subject: [PATCH] fix(collections): restore list items in posts with card indicator Co-Authored-By: Claude Opus 4.7 (1M context) --- .../collections/class-content-inserter.php | 3 ++- .../class-test-content-inserter.php | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/includes/collections/class-content-inserter.php b/includes/collections/class-content-inserter.php index ab8095c100..a45d097b61 100644 --- a/includes/collections/class-content-inserter.php +++ b/includes/collections/class-content-inserter.php @@ -264,7 +264,8 @@ function ( $block ) use ( $blocks_to_skip_empty ) { // Insert after the nth block. $rendered_content = ''; foreach ( $parsed_blocks as $index => $block ) { - $rendered_content .= $block['innerHTML']; + // Use render_block() so inner blocks (e.g. core/list-item children of core/list) and dynamic blocks are emitted. + $rendered_content .= render_block( $block ); // Insert after the nth block (index is 0-based). if ( $index === $nth_block - 1 ) { diff --git a/tests/unit-tests/collections/class-test-content-inserter.php b/tests/unit-tests/collections/class-test-content-inserter.php index 6bea31c0f7..544b0eb4a8 100644 --- a/tests/unit-tests/collections/class-test-content-inserter.php +++ b/tests/unit-tests/collections/class-test-content-inserter.php @@ -278,6 +278,29 @@ public function test_insert_after_nth_block() { $this->assertLessThan( $third_pos, $insert_pos, 'Inserted content should come before third paragraph.' ); } + /** + * Test insert_after_nth_block preserves inner blocks (e.g., list items). + * + * Regression: a `core/list` block stores its `
  • ` items as `core/list-item` + * inner blocks, not in `innerHTML`. The same applies to columns, groups, + * buttons, etc. Reassembling parsed blocks must use `render_block()` so + * inner-block content (and dynamic blocks) are emitted. + * + * @covers \Newspack\Collections\Content_Inserter::insert_after_nth_block + */ + public function test_insert_after_nth_block_preserves_inner_blocks() { + $insert_html = '
    Inserted content
    '; + + $block_content = "\n

    First paragraph.

    \n\n\n" + . "\n

    Second paragraph.

    \n\n\n" + . "\n
      \n
    • Item one
    • \n\n\n\n
    • Item two
    • \n
    \n"; + + $result = Content_Inserter::insert_after_nth_block( $block_content, $insert_html, 2 ); + + $this->assertStringContainsString( '
  • Item one
  • ', $result, 'First list item should be preserved.' ); + $this->assertStringContainsString( '
  • Item two
  • ', $result, 'Second list item should be preserved.' ); + } + /** * Test check_if_post_is_in_collection excludes draft collections. *