facebookarchive / facebook-instant-articles-sdk-php

The Facebook Instant Articles SDK for PHP provides a native interface for creating and publishing Instant Articles.
https://instantarticles.fb.com/
Other
232 stars 148 forks source link

Transformer drops content in pharagraph if there is image too #91

Closed katazina closed 8 years ago

katazina commented 8 years ago

The content: <p><a href="http://example.com/image.jpg"><img class="alignnone size-medium wp-image-45" src="http://example.com/image.jpg" alt="imagealt" width="300" height="169" /></a>Some text comes here and some more and more ... and some.</p>

After the closing <a> tag, there is some text, and the sdk drops that text.

Same happens when I reorder the inside: <p>Some text comes here and some more and more ... and some.<a href="http://example.com/image.jpg"><img class="alignnone size-medium wp-image-45" src="http://example.com/image.jpg" alt="imagealt" width="300" height="169" /></a></p>

Or if there is text before and after: <p>Some text comes here and some more and more ... and some.<a href="http://example.com/image.jpg"><img class="alignnone size-medium wp-image-45" src="http://example.com/image.jpg" alt="imagealt" width="300" height="169" /></a>Some text comes here and some more and more ... and some.</p>

The below expexted result is just for the first content example.

Expected Result

<figure>
        <img src="http://example.com/image.jpg"/>
</figure>
<p>Some text comes here and some more and more ... and some.</p>

Actual Result

<figure>
        <img src="http://example.com/image.jpg"/>
</figure>
demoive commented 8 years ago

Also reported on the WordPress forums:

https://wordpress.org/support/topic/articles-that-begin-with-an-image-are-stripping-out-first-paragraph?replies=2 https://wordpress.org/support/topic/content-within-div-missing-in-instant-article-and-other-content-missing?replies=2

everton-rosario commented 8 years ago

@katazina Can you help us validating this PR that fixes your issue?

katazina commented 8 years ago

unfortunately it's not working for me. I downloaded a patch file, after that I downloaded the whole paragraph-with-image branch, but no success.

Try with the attached post content. paragraph-image.txt

diegoquinteiro commented 8 years ago

@katazina did you configure the new rule on your ruleset JSON? If so, can you share how your JSON looks like?

katazina commented 8 years ago

Sorry, it's night here. I refreshed the json file, but now I got an error when the feed is generated:

PHP Fatal error: Call to undefined method Facebook\InstantArticles\Elements\InstantArticle::appendText() in facebook-instant-articles-sdk-php/src/Facebook/InstantArticles/Transformer/Rules/TextNodeRule.php on line 48

I'm trying to figure it out what happened.

katazina commented 8 years ago

I'm sorry, I had no time to check it. Now I did. It's half good, but still not perfect.

Here is a code which on the transformer fails:

<p><img class="alignleft size-medium wp-image-5545280" src="https://pixabay.com/static/uploads/photo/2015/10/01/20/15/landscape-967630_960_720.jpg" alt="something" width="320" height="213" />almafa fsdfsdff8</p>
<p>sfsdfsd</p>
<p>3333sdfsdfsd</p>
<ul>
<li>some text <a href="https://pixabay.com/static/uploads/photo/2015/10/01/20/15/landscape-967630_960_720.jpg"><img src="https://pixabay.com/static/uploads/photo/2015/10/01/20/15/landscape-967630_960_720.jpg" width="600" height="360" /></a></li>
</ul>
<p>sfdsfsdf</p>
<p>sfsdfsd</p>
<p>fssd</p>

And here is the current result:

<figure>
    <img src="https://pixabay.com/static/uploads/photo/2015/10/01/20/15/landscape-967630_960_720.jpg"/>
</figure>
<p>almafa fsdfsdff8</p>
<p>sfsdfsd</p>
<p>3333sdfsdfsd</p>
<ul>
    <li>some text <a href="https://pixabay.com/static/uploads/photo/2015/10/01/20/15/landscape-967630_960_720.jpg"></a></li>
</ul>
<p>sfdsfsdf</p>
<p>sfsdfsd</p>
<p>fssd</p>

You can see, beside the some text the image is not processed, but an empty a tag was kept.

With the p tag in the first line, it worked perfectly.