mozilla / mozilla/readability

Preserve videos in paragraphs

Open
#957 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
11.5k
Forks
732
PR merge metrics
No merged PRs in 30d

Description

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @mozilla/readability@0.5.0 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/@mozilla/readability/Readability.js b/node_modules/@mozilla/readability/Readability.js
index b745aa0..970538b 100644
--- a/node_modules/@mozilla/readability/Readability.js
+++ b/node_modules/@mozilla/readability/Readability.js
@@ -715,11 +715,12 @@ Readability.prototype = {
     // Remove extra paragraphs
     this._removeNodes(this._getAllNodesWithTag(articleContent, ["p"]), function (paragraph) {
       var imgCount = paragraph.getElementsByTagName("img").length;
+      var videoCount = paragraph.getElementsByTagName("video").length;
       var embedCount = paragraph.getElementsByTagName("embed").length;
       var objectCount = paragraph.getElementsByTagName("object").length;
       // At this point, nasty iframes have been removed, only remain embedded video ones.
       var iframeCount = paragraph.getElementsByTagName("iframe").length;
-      var totalCount = imgCount + embedCount + objectCount + iframeCount;
+      var totalCount = imgCount + videoCount + embedCount + objectCount + iframeCount;
 
       return totalCount === 0 && !this._getInnerText(paragraph, false);
     });

If I don't apply this change, the video on this website will be removed.

Image

Do you think we can open a PR to fix it?

This issue body was partially generated by patch-package.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Readability.js at the “Remove extra paragraphs” logic shown in the issue, and compare it with the supplied patch. Verify the article extraction behavior on the linked Shortwave page and confirm that videos inside paragraphs are preserved rather than removed.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.