Fix #1012: Prevent aggressive stripping of below/bellow header content wrappers - #1015
Fix #1012: Prevent aggressive stripping of below/bellow header content wrappers#1015hanumanraj07 wants to merge 2 commits into
Conversation
gijsk
left a comment
There was a problem hiding this comment.
Thanks for the PR.
Unfortunately, it doesn't seem reasonable to treat "below" as semantically indicating "this is important article text" - even worse for "bellow".
Is there no other markup that can be used to make this determination? And/or, is there evidence that this class name structure is common for other sites than knowablemagazine.org, due to common CMSes or similar?
Also, please add a testcase to the testcases folder for this so we don't regress it in future - you can use the generate-testcase.js script to do this easily.
gijsk
left a comment
There was a problem hiding this comment.
Doesn't look like the PR changed since last time? I already left a comment before.
|
I'm closing this PR. After further investigation, adding below and bellow to okMaybeItsACandidate is too generic and doesn't semantically indicate the main article content. We tried an alternative approach (adding word boundaries to header in unlikelyCandidates like \bheader\b) which correctly safeguards bellowheadercontainer, but this unfortunately broke several existing test cases (like the SRE book) where valid sub-headers were no longer stripped out. Given that knowablemagazine.org hides its real content behind Cloudflare's CAPTCHA block and doesn't appear to have any other standard semantic markup on the article container, this seems to be a site-specific parsing failure that is not safely fixable on a global level. Thanks for your review! |
Fixes #1012
Description
Currently, Readability fails to parse articles on sites like
knowablemagazine.orgwhere the main content is wrapped inside a container with a class such asbellowheadercontainer.The
unlikelyCandidatesregex aggressively strips out elements containing the wordheaderwithout checking for word boundaries. As a result, structural containers using class names likebelow-headerorbellowheaderare prematurely removed from the DOM, causing Readability to completely miss the main article content and fallback to parsing unrelated footer elements.This PR adds
belowand its common typobellowto theokMaybeItsACandidatesafeguard regex. This ensures that classes indicating placement beneath a header (which frequently wrap the main article content) bypass theunlikelyCandidatespurge and receive a proper chance to be scored.Testing
okMaybeItsACandidatecorrectly safeguards the article container to resolve the parsing failure in knowablemagazine.org - Does not show the article, republish message displayed after enabling reader mode #1012.