|
@@ -25,7 +25,7 @@
|
|
|
* @param {HTMLDocument} doc The document to parse.
|
|
* @param {HTMLDocument} doc The document to parse.
|
|
|
* @param {Object} options The options object.
|
|
* @param {Object} options The options object.
|
|
|
*/
|
|
*/
|
|
|
-function Readability(doc, options) {
|
|
|
|
|
|
|
+ function Readability(doc, options) {
|
|
|
// In some older versions, people passed a URI as the first argument. Cope:
|
|
// In some older versions, people passed a URI as the first argument. Cope:
|
|
|
if (options && options.documentElement) {
|
|
if (options && options.documentElement) {
|
|
|
doc = options;
|
|
doc = options;
|
|
@@ -390,8 +390,8 @@ Readability.prototype = {
|
|
|
} else {
|
|
} else {
|
|
|
// if the link has multiple children, they should all be preserved
|
|
// if the link has multiple children, they should all be preserved
|
|
|
var container = this._doc.createElement("span");
|
|
var container = this._doc.createElement("span");
|
|
|
- while (link.childNodes.length > 0) {
|
|
|
|
|
- container.appendChild(link.childNodes[0]);
|
|
|
|
|
|
|
+ while (link.firstChild) {
|
|
|
|
|
+ container.appendChild(link.firstChild);
|
|
|
}
|
|
}
|
|
|
link.parentNode.replaceChild(container, link);
|
|
link.parentNode.replaceChild(container, link);
|
|
|
}
|
|
}
|
|
@@ -1085,10 +1085,9 @@ Readability.prototype = {
|
|
|
neededToCreateTopCandidate = true;
|
|
neededToCreateTopCandidate = true;
|
|
|
// Move everything (not just elements, also text nodes etc.) into the container
|
|
// Move everything (not just elements, also text nodes etc.) into the container
|
|
|
// so we even include text directly in the body:
|
|
// so we even include text directly in the body:
|
|
|
- var kids = page.childNodes;
|
|
|
|
|
- while (kids.length) {
|
|
|
|
|
- this.log("Moving child out:", kids[0]);
|
|
|
|
|
- topCandidate.appendChild(kids[0]);
|
|
|
|
|
|
|
+ while (page.firstChild) {
|
|
|
|
|
+ this.log("Moving child out:", page.firstChild);
|
|
|
|
|
+ topCandidate.appendChild(page.firstChild);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
page.appendChild(topCandidate);
|
|
page.appendChild(topCandidate);
|
|
@@ -1219,6 +1218,9 @@ Readability.prototype = {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
articleContent.appendChild(sibling);
|
|
articleContent.appendChild(sibling);
|
|
|
|
|
+ // Fetch children again to make it compatible
|
|
|
|
|
+ // with DOM parsers without live collection support.
|
|
|
|
|
+ siblings = parentOfTopCandidate.children;
|
|
|
// siblings is a reference to the children array, and
|
|
// siblings is a reference to the children array, and
|
|
|
// sibling is removed from the array when we call appendChild().
|
|
// sibling is removed from the array when we call appendChild().
|
|
|
// As a result, we must revisit this index since the nodes
|
|
// As a result, we must revisit this index since the nodes
|
|
@@ -1246,9 +1248,8 @@ Readability.prototype = {
|
|
|
var div = doc.createElement("DIV");
|
|
var div = doc.createElement("DIV");
|
|
|
div.id = "readability-page-1";
|
|
div.id = "readability-page-1";
|
|
|
div.className = "page";
|
|
div.className = "page";
|
|
|
- var children = articleContent.childNodes;
|
|
|
|
|
- while (children.length) {
|
|
|
|
|
- div.appendChild(children[0]);
|
|
|
|
|
|
|
+ while (articleContent.firstChild) {
|
|
|
|
|
+ div.appendChild(articleContent.firstChild);
|
|
|
}
|
|
}
|
|
|
articleContent.appendChild(div);
|
|
articleContent.appendChild(div);
|
|
|
}
|
|
}
|
|
@@ -1886,7 +1887,7 @@ Readability.prototype = {
|
|
|
/**
|
|
/**
|
|
|
* Look for 'data' (as opposed to 'layout') tables, for which we use
|
|
* Look for 'data' (as opposed to 'layout') tables, for which we use
|
|
|
* similar checks as
|
|
* similar checks as
|
|
|
- * https://dxr.mozilla.org/mozilla-central/rev/71224049c0b52ab190564d3ea0eab089a159a4cf/accessible/html/HTMLTableAccessible.cpp#920
|
|
|
|
|
|
|
+ * https://searchfox.org/mozilla-central/rev/f82d5c549f046cb64ce5602bfd894b7ae807c8f8/accessible/generic/TableAccessible.cpp#19
|
|
|
*/
|
|
*/
|
|
|
_markDataTables: function(root) {
|
|
_markDataTables: function(root) {
|
|
|
var tables = root.getElementsByTagName("table");
|
|
var tables = root.getElementsByTagName("table");
|
|
@@ -1986,7 +1987,7 @@ Readability.prototype = {
|
|
|
|
|
|
|
|
for (var j = 0; j < elem.attributes.length; j++) {
|
|
for (var j = 0; j < elem.attributes.length; j++) {
|
|
|
attr = elem.attributes[j];
|
|
attr = elem.attributes[j];
|
|
|
- if (attr.name === "src" || attr.name === "srcset") {
|
|
|
|
|
|
|
+ if (attr.name === "src" || attr.name === "srcset" || attr.name === "alt") {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
var copyTo = null;
|
|
var copyTo = null;
|