Make WordPress Core

Opened 6 weeks ago

Last modified 3 weeks ago

#62966 new defect (bug)

PHP output of get_comment_delimited_block_content does not match Gutenberg JS output

Reported by: kevinfodness's profile kevinfodness Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: trunk
Component: Editor Keywords: has-patch
Focuses: Cc:

Description

The get_comment_delimited_block_content function (in PHP) does not produce the same output as block content created in Gutenberg.

For example, if I create a new post using the block editor and add a paragraph block with the text "This is a paragraph." and save it, the following markup gets saved to post_content:

<!-- wp:paragraph -->
<p>This is a paragraph.</p>
<!-- /wp:paragraph -->

However, if I attempt to do the same thing using the get_comment_delimited_block_content:

get_comment_delimited_block_content( 'paragraph', [], '<p>This is a paragraph.</p>' );

the output lacks the line breaks:

<!-- wp:paragraph --><p>This is a paragraph.</p><!-- /wp:paragraph -->

This presents problems for PHP code that produces Gutenberg markup (e.g., in data migrations) because what is saved to the database by using this function is not the same as what would be saved if the user edited the content directly in Gutenberg, which may have unintentional side effects down the line if code expects there to be line breaks after the opening comment and before the closing comment as it is written by Gutenberg JS.

The output of get_comment_delimited_block_content in PHP should match what is generated by Gutenberg's JavaScript. At a minimum, the function should be modified so that when block contents are provided, there are line breaks after the opening comment and before the closing comment, but there may be other areas where the output doesn't match exactly that should be brought into parity as well.

(Note: While this applies to block editor functionality, the code in question lives in wp-includes/blocks.php which is part of Core, not the Gutenberg GitHub repo.)

Change History (1)

This ticket was mentioned in PR #8452 on WordPress/wordpress-develop by @snehapatil02.


3 weeks ago
#1

  • Keywords has-patch added; needs-patch removed

…e closing block comment to match the formatting used by Gutenberg’s JavaScript.

Trac ticket: https://core.trac.wordpress.org/ticket/62966

Note: See TracTickets for help on using tickets.