timber icon indicating copy to clipboard operation
timber copied to clipboard

post.preview doesn't work if not ending with </p> tag

Open claudiopedrom opened this issue 5 years ago • 6 comments

Expected behavior

Get all the preview that I've defined in the Post.

Actual behavior

If I define a More Tag right after an element like a <ul> or <img> the post preview will only show my last <p> element and will ignore all later elements.

So I'm forced to write all tags: {{ post.preview.read_more(false).strip('<div><p><ul><ol><li><a><img>') }}

Steps to reproduce behavior

  1. Create a WordPress post and write something with this structure:
<p></p>
<p></p>
<ul></ul>
<!--more  -->
<p></p>

{{ post.preview.read_more(false).strip(false) }}

After some testing the problem seems to be on this line: https://github.com/timber/timber/blob/2cdb07fdd2baa05907d5457f4e621549540f427e/lib/PostPreview.php#L229

claudiopedrom avatar Nov 11 '19 15:11 claudiopedrom

Same issue here.

rgllm avatar Nov 11 '19 15:11 rgllm

@claudiopedrom yes you're right about where is the problem.

I think that now, when many of us is using the Gutenberg editor the chance when we'll end the text in more with something else than </p> are much greater than before so this rules may only cause more trouble.

I think that, for keeping everything backward compatible we should:

  • by default leave this exactly how it's working
  • add some extra variable to the if if ( !$this->strip && !$this->new_behaviour ) {
  • create a filter for the new variable so by default it will be false but if someone would prefer to change it true
  • be new behaviour I think that the user should responsible where they put the <!--more--> tag.
  • at some point - remove this part of code

palmiak avatar Nov 17 '19 23:11 palmiak

@claudiopedrom @rgllm thanks for the tip and the very very helpful full description.

@palmiak does a great job of laying out steps to resolve. Given the likely change for existing behavior, I'd suggest just PR'ing this into 2.0 so we can jettison legacy support. Anyone want to claim?

jarednova avatar Nov 19 '19 19:11 jarednova

@jarednova so you think we should leave version 1.x as it is and prepare just for 2.0 or prepare both versions for 1.x with legacy support and 2.x without?

palmiak avatar Nov 19 '19 23:11 palmiak

I'd say let's start with 2.x (without legacy support). Once there, we can port that into 1.x and add in legacy support!

jarednova avatar Nov 20 '19 14:11 jarednova

Added the 2.x tag for good measure.

Levdbas avatar May 12 '23 11:05 Levdbas