Opened 6 years ago
Closed 6 years ago
#46471 closed defect (bug) (fixed)
Malformed content when using the More block and stripping the teaser
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.2 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Editor | Keywords: | has-patch needs-testing |
Focuses: | Cc: |
Description
When using the_content()
and specifying the $strip_teaser
argument as true
, the output contains a malformed "More" block.
Steps to reproduce:
- In your theme's
single
template, output content using<?php the_content( null, true ); ?>
- Create a a post that includes multiple paragraph blocks, separated by a single More block
The expected output is:
<span id="more-123"></span> <p>Second block.</p>
The actual output is:
<span id="more-123"></span> <!-- /wp:more --> <!-- wp:paragraph --> <p>Second block.</p> <!-- /wp:paragraph -->
Notice that the closing <!-- /wp:more -->
tag exists, but the opening one doesn't. Additionally, the malformed block tag at the beginning causes none of the other block tags to be cleaned up.
Most importantly, it breaks any dynamic blocks completed.
Attachments (5)
Change History (13)
#2
@
6 years ago
Looks Good, Works As Expected
Hi @lukecarbis,
This looks good. Like you mentioned, I also saw that this removed the extra <!-- /wp:more -->
comment.
The single post template looks good, as does the 'Posts' page with multiple posts (shown above).
@
6 years ago
Minor grammar fix for the comment. 'it's' indicates 'it is', but the sentence needed 'it has' to read properly.
#4
@
6 years ago
As mentioned, the content can be dived through <!--more(.*?)?-->
regardless of any More block wrappers around it, leaving unclosed More block tags in each part.
I guess one could enhance that splitting with preg_split()
but I think that would not be as clean and simple as in 46471.1.diff.
Currently 46471.1.diff runs the preg_replacement
, regardless if there are any blocks in the content or not. The has_block( 'more', $content )
(passing content to avoid get_post
) comes to mind or a simple strpos
check. I would expect the strpos
vs preg_replace
performance would only show up for very large content and multiple calls.
Maybe this More block content check is not needed as I can imagine more and more content will contain blocks.
We can also see this with the_content()
when using the noteaser text tag.
Example:
<!-- wp:paragraph --> <p>Teaser part.</p> <!-- /wp:paragraph --> <!-- wp:more --> <!--more--> <!--noteaser--> <!-- /wp:more --> <!-- wp:paragraph --> <p>Second block.</p> <!-- /wp:paragraph -->
The patch in 46471-2.diff is a first iteration of tests for 46471.1.diff.
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
6 years ago
#7
@
6 years ago
This is somewhat similar to #46133. Ideally the post content should be split on <!--more-->
after the blocks have been parsed. As that's not possible, seems the only way to fix this is to treat the <!-- wp:more ... -->
block same as the <!--more-->
tag: split the post at that place and remove the tag and the block.
Looking at 46471-2.diff, it seems to work properly (I know, parsing strings out of HTML with regex is...). Wondering if it would be a bit better to do a str_replace() for the block end delimiter. Makes the regex a tiny bit simpler and we need to run it only on the first part of the split post_content.
This patch removes the
<!-- wp:more -->
starting block tag from the teaser, and the<!-- /wp:more –>
closing block tag from the main content.