FB55/readabilitySAX — Issue #11: Unwanted elements showing after last change
Author: imanel
Created: 2012-01-15 00:15:02+00:00
State: open

After commit ec72bae8f6807f35fca5d7073c867859f8b8ca49 some unwanted elements started showing. Example (like in earlier issues): http://www.appleinsider.com/articles/12/01/14/reacting_to_apple_at_ces_2012_intels_ultrabooks_to_samsungs_galaxy_note.html

Artifacts:

- In starting paragraph there are strange table that isn't visible on page. After small investigation it looks that there is table with script tag that is trimmed, but empty table is still present.
- Link to next page is no longer removed - it was removed earlier, but not it's moved outside of div and used as normal element.

Sidenote: it looks that reverting this commit is making it work again, but images are removed. Fix for that could be setting cleanConditionally to false, but then table is showed again(in both HEAD version and reverted version)

As for images - it looks that it's not fault of [line 471](https://github.com/FB55/readabilitySAX/blob/ec72bae8f6807f35fca5d7073c867859f8b8ca49/readabilitySAX.js#L471) - we have there only one image per div, so conditions are valid. What is stripping images is both [line 468](https://github.com/FB55/readabilitySAX/blob/ec72bae8f6807f35fca5d7073c867859f8b8ca49/readabilitySAX.js#L468) and [line 472-475](https://github.com/FB55/readabilitySAX/blob/ec72bae8f6807f35fca5d7073c867859f8b8ca49/readabilitySAX.js#L472-L475)

Explanation:

- line 468 is removing img because there are not enough paragraphs per site(more images tha paragraphs) One reason for that is that changing double br tags to paragraph is not counted for paragraph count. Second one is that in this case if image is posted as first item in article then no paragraphs are yet available so it will be stripped. But that usually is not the problem because in most cases image before first paragraph is just teaser and can be safely removed. So we just need to start counting double br as paragraph.
- line 472-475 - I'm not 100% sure how it is working, but it looks like density is wrongly calculated(but it's just guess) for images inside of divs.