Reduce down singly nested containers when returning final content from the readability algorithm
@evanxd is already working on this.
Since Jan 23, 2017.
Assessment
This issue has not been assessed yet.
Description
In #337 we started replacing candidate container elements with their parents if they had no siblings. This helped in cases where major blocks of text were deeply nested and we were therefore unable to detect their siblings.
However, there are 2 downsides:
- we end up adding needless
<div>and similar nesting to elements that, given the lack of styling for them, adds no value to the readability result. - we no longer correctly detect
dirattributes on the container element, because the container element has changed.
We should fix this by having an algorithm (after all the cleanup etc., once we're sure we're returning a particular candidate element) that does 3 things:
- while the candidate has exactly 1 element child node and no non-whitespace text children, make its child the top candidate
- in that case, if the parent has a
dirattribute and the child does not, set thediron the child. (If the child has adirattribute, that direction should "win", ie persist.) - if the final candidate we land on this way is not
<p>or<div>or<article>or<section>, create a<div>and put all the child nodes (not just elements!) in that<div>and return that<div>. This will fix cases where we'd otherwise return<table>or<td>elements.
@evanxd, can you take this on?
- Dominant language
- JavaScript
- Stars
- 11.5k
- Forks
- 732
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mozilla/readability
-
Difficulty 1/5 Under an hour Newbie friendliness 76/100
mozilla/readability#1026 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
mozilla/readability#997 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 58/100
mozilla/readability#1031 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
mozilla/readability#1029 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 58/100
mozilla/readability#1024 ·
All issues in mozilla/readability
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
babalae/bettergi-scripts-list#3674 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
vadimdemedes/ink#1029 ·
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
optimization optimization:agents-md-curator
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
githubnext/gh-aw-cao#13143 ·