Make WordPress Core

#51302 closed defect (bug) (duplicate)

Lots of newlines in REST API rendered content when using block editor

Reported by: rmens Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.5.1
Component: Editor Keywords:
Focuses: rest-api Cc:

Description

In a post created with the block editor i have the following

<!-- wp:paragraph -->
<p>This is paragraph 1</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This is paragraph 2</p>
<!-- /wp:paragraph -->

But the REST API renders the content as

"\n<p>This is paragraph 1</p>\n\n\n\n<p>This is paragraph 2</p>\n"

There seem to be 4 newlines between the paragraphs, while there should only be one. When I make the same post in the classic editor, it comes out like this. Which looks more correct.

"<p>This is paragraph 1</p>\n<p>This is paragraph 2</p>\n"

Change History (4)

#1 @joyously
17 months ago

Are the block marker comments being converted to \n?

#2 @rmens
17 months ago

Hi @joyously, after some more testing this does seem to be the case. Normal HTML-comments like <!-- this is a comment --> don't convert to \n but block markers are.

The difference in rendered content between the classic editor and block editor is the most problematic in this case. When there are some posts made with the classic editor and some with the block editor, the rendered output is no longer predictable.

Last edited 17 months ago by rmens (previous) (diff)

#3 @TimothyBlynJacobs
17 months ago

  • Component changed from REST API to Editor
  • Focuses rest-api added

I'm moving this to the Editor component as it is responsible for rendering the raw content, the REST API only applies the the_content filter.

#4 @SergeyBiryukov
16 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi there, welcome back to WordPress Trac!

Thanks for the report, we're already tracking this issue in #46655.

Note: See TracTickets for help on using tickets.