From 254eaeb7132e4625ff4d235a73d76fcee7efbe92 Mon Sep 17 00:00:00 2001 From: Tyler Hallada Date: Tue, 18 Aug 2026 02:51:28 +0000 Subject: [PATCH] Fix the six ways article images went missing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Across the first three issues, 145 of 208 referenced images reached the page; 38 that had been downloaded, re-encoded and written into the EPUB were never referenced by any chapter, and 69 became `[image: …]` lines. Six independent causes, each verified against the real articles: - **Entity-encoded URLs never matched their asset.** `prepare_body` re-runs `ammonia::clean`, which writes `&` as `&`, and the tag scanner that looks the asset up compared raw attribute text against a URL a real parser had decoded. Every image with a query string lost. `parse_attrs` now decodes entities. - **Readability clobbers a working `src`.** Its lazy-image heuristic copies any attribute containing `.jpg` over `src`, which on NPR meant a `{width}` template (the CDN answers those with a grey square reading "Image"), on Substack a JSON blob, on dfarq an entire `srcset` string. Pages are now normalized before readability sees them: every `` is reduced to `src`/`alt`/`title` with the best candidate from the lazy attributes, `src`, `srcset` and ``, so there is nothing left for the heuristic to substitute. Candidates that cannot resolve — braces, whitespace, quotes, `data:` — are rejected by shape rather than by publisher. - **Readability deletes `