From d2bb359f5c085dac2b8ced55f5337f1f857c3341 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Tue, 26 Apr 2022 15:18:23 -0700 Subject: [PATCH] Handle srcset image density specifications --- packages/readabilityjs/Readability.js | 2 +- .../readabilityjs/test/test-readability.js | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/readabilityjs/Readability.js b/packages/readabilityjs/Readability.js index c68b5de88..2386c594d 100644 --- a/packages/readabilityjs/Readability.js +++ b/packages/readabilityjs/Readability.js @@ -562,7 +562,7 @@ Readability.prototype = { if (d) { const proxySrc = this.createImageProxyUrl(this.toAbsoluteURI(link)); - resultSrcset += `${proxySrc} ${d},`; + resultSrcset += `${proxySrc} ${d}x,`; } } diff --git a/packages/readabilityjs/test/test-readability.js b/packages/readabilityjs/test/test-readability.js index 44c00e44b..6ccbbc563 100644 --- a/packages/readabilityjs/test/test-readability.js +++ b/packages/readabilityjs/test/test-readability.js @@ -281,6 +281,27 @@ describe("Readability API", function() { var content = new Readability(dom.window.document).parse().content; expect(content).eql(expected_xhtml); }); + + it("should handle srcset elements with density descriptors", function() { + var dom = new JSDOM('My image: ' + ); + var expected_xhtml = '
My image: ' + + '
'; + var content = new Readability(dom.window.document, { + createImageProxyUrl: function(url) { + return url; + } + }).parse().content; + expect(content).eql(expected_xhtml); + }); }); });