Skip to content

Commit

Permalink
exclude additional elements based on their role (mozilla#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
PalmerAL authored Aug 24, 2020
1 parent 3fe8281 commit d5eea06
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
6 changes: 4 additions & 2 deletions Readability.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ Readability.prototype = {
jsonLdArticleTypes: /^Article|AdvertiserContentArticle|NewsArticle|AnalysisNewsArticle|AskPublicNewsArticle|BackgroundNewsArticle|OpinionNewsArticle|ReportageNewsArticle|ReviewNewsArticle|Report|SatiricalArticle|ScholarlyArticle|MedicalScholarlyArticle|SocialMediaPosting|BlogPosting|LiveBlogPosting|DiscussionForumPosting|TechArticle|APIReference$/
},

UNLIKELY_ROLES: [ "menu", "menubar", "complementary", "navigation", "alert", "alertdialog", "dialog" ],

DIV_TO_P_ELEMS: [ "A", "BLOCKQUOTE", "DL", "DIV", "IMG", "OL", "P", "PRE", "TABLE", "UL", "SELECT" ],

ALTER_TO_DIV_EXCEPTIONS: ["DIV", "ARTICLE", "SECTION", "P"],
Expand Down Expand Up @@ -917,8 +919,8 @@ Readability.prototype = {
continue;
}

if (node.getAttribute("role") == "complementary") {
this.log("Removing complementary content - " + matchString);
if (this.UNLIKELY_ROLES.includes(node.getAttribute("role"))) {
this.log("Removing content with role " + node.getAttribute("role") + " - " + matchString);
node = this._removeAndGetNext(node);
continue;
}
Expand Down
4 changes: 0 additions & 4 deletions test/test-pages/nytimes-1/expected.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,5 @@
</div>
</article>
</main>
<section id="site-index">
<nav id="site-index-navigation" role="navigation">
</nav>
</section>
</div>
</div>
4 changes: 0 additions & 4 deletions test/test-pages/nytimes-2/expected.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,5 @@
</div>
</article>
</main>
<section id="site-index">
<nav id="site-index-navigation" role="navigation">
</nav>
</section>
</div>
</div>

0 comments on commit d5eea06

Please sign in to comment.