Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Lists of Images Not Showing #738

Merged
merged 9 commits into from
Nov 18, 2022
Merged

Fixed Lists of Images Not Showing #738

merged 9 commits into from
Nov 18, 2022

Conversation

Tuxy222
Copy link
Contributor

@Tuxy222 Tuxy222 commented Mar 9, 2022

This change allows for lists of images within the content of the page to be present in reader mode.

Related to: #697

Copy link
Contributor

@niklasbaumgardner niklasbaumgardner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just have a few things to address. Thanks for working on this!

Readability.js Outdated
@@ -2109,6 +2109,7 @@ Readability.prototype = {
var embedCount = 0;
var embeds = this._getAllNodesWithTag(node, ["object", "embed", "iframe"]);


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We can remove this empty line

Readability.js Outdated
}
}
// Allow lists of images to remain, so long as img count doesn't exceed li count
if (img > 1 && img <= (li+100)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we add 100 to li here?

Readability.js Outdated
}
}
// Allow lists of images to remain, so long as img count doesn't exceed li count
if (img > 1 && img <= (li+100)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we add 100 to li here?

Readability.js Outdated
@@ -2136,6 +2137,29 @@ Readability.prototype = {
(!isList && weight < 25 && linkDensity > 0.2) ||
(weight >= 25 && linkDensity > 0.5) ||
((embedCount === 1 && contentLength < 75) || embedCount > 1);

if (haveToRemove) {
// Check for lists of images
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having comments on each line, could we have one comment at the beginning explaining why we are doing this check?

Readability.js Outdated
@@ -2136,6 +2137,29 @@ Readability.prototype = {
(!isList && weight < 25 && linkDensity > 0.2) ||
(weight >= 25 && linkDensity > 0.5) ||
((embedCount === 1 && contentLength < 75) || embedCount > 1);

if (haveToRemove) {
// Check for lists of images
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having comments on each line, could we have one comment at the beginning explaining why we are doing this check?

Readability.js Outdated
@@ -2109,6 +2109,7 @@ Readability.prototype = {
var embedCount = 0;
var embeds = this._getAllNodesWithTag(node, ["object", "embed", "iframe"]);


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this extra newline

Readability.js Outdated
Comment on lines 2144 to 2155
if (node.children[x].localName == "li") {
if (node.children[x].children.length > 1) {
return true;
}
} else {
return true;
}
}
li_count = node.getElementsByTagName("li").length;
if (img > 1 && img <= (li_count)) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (node.children[x].localName == "li") {
if (node.children[x].children.length > 1) {
return true;
}
} else {
return true;
}
}
li_count = node.getElementsByTagName("li").length;
if (img > 1 && img <= (li_count)) {
return false;
}
let child = node.children[x];
if (child.localName == "li" && child.children.length) {
return true;
}
li_count = node.getElementsByTagName("li").length;
if (img > 1 && img <= (li_count)) {
return false;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be a good idea to document here why we remove some images for this specific case. It's not immediately clear to me here.

Readability.js Outdated
Comment on lines 2144 to 2155
if (node.children[x].localName == "li") {
if (node.children[x].children.length > 1) {
return true;
}
} else {
return true;
}
}
li_count = node.getElementsByTagName("li").length;
if (img > 1 && img <= (li_count)) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be a good idea to document here why we remove some images for this specific case. It's not immediately clear to me here.

@tigleym
Copy link
Contributor

tigleym commented Mar 25, 2022

It looks like we have one failing test here. Could you investigate it?

@tigleym
Copy link
Contributor

tigleym commented Mar 30, 2022

Nice! Thanks @Tuxy222 . Do you think we can create a test case for this?

@Tuxy222 Tuxy222 requested a review from tigleym April 15, 2022 00:37
Copy link
Contributor

@niklasbaumgardner niklasbaumgardner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just have a nit to fix. Otherwise, I think this is good

Co-authored-by: niklasbaumgardner <63427453+niklasbaumgardner@users.noreply.github.com>
Copy link
Contributor

@tigleym tigleym left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@tholu
Copy link
Contributor

tholu commented Nov 18, 2022

Will this be merged? Or why not?

@gijsk gijsk merged commit 7c7f694 into mozilla:master Nov 18, 2022
@gijsk
Copy link
Contributor

gijsk commented Nov 18, 2022

I think this just got lost. I just merged it.

@gijsk
Copy link
Contributor

gijsk commented Nov 18, 2022

(Thanks for the ping!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants