From 6fed28610d6e621dbc53a1ab8fc683ab5e4df2e9 Mon Sep 17 00:00:00 2001 From: Radhi Fadlillah Date: Tue, 31 Mar 2020 11:18:01 +0700 Subject: [PATCH] Simplify loop for unwrapping noscript --- Readability.js | 57 +++++++++++------------ test/test-pages/bug-1255978/expected.html | 25 ++++++---- test/test-pages/mozilla-1/expected.html | 4 +- 3 files changed, 44 insertions(+), 42 deletions(-) diff --git a/Readability.js b/Readability.js index 3987162..13fde74 100644 --- a/Readability.js +++ b/Readability.js @@ -1316,6 +1316,19 @@ Readability.prototype = { return metadata; }, + /** + * Check if node is image, or if node contains exactly only one image + * whether as a direct child or as its descendants. + * + * @param Element + **/ + _isSingleImage: function(node) { + if (node.tagName === "IMG") return true; + if (node.children.length !== 1) return false; + if (node.textContent.trim() !== "") return false; + return this._isSingleImage(node.children[0]); + }, + /** * Find all