Problem/Motivation

Two related gaps in how StaticGenerator::getHtmlAssets() extracts image URLs from rendered HTML for the static export.

1. Srcset parser drops all but the first URL when srcset has no space after commas

The current parser strips size descriptors with this regex before exploding on spaces:

preg_replace('/ [^ ]+(,|$)/', '', $srcset)

The regex requires a space before the size descriptor. Drupal core's responsive image style renderer commonly emits srcset values with no space after the comma:

/files/image1.jpg 650w,/files/image2.jpg 870w,/files/image3.jpg 1090w

In that form, the comma is just another non-space character to [^ ]+, so the regex matches the entire trailing run as a single descriptor. preg_replace strips it. The subsequent explode(' ', ...) then yields one element — a concatenated garbage path made of the
leading URL plus the next URL fragment. Only the first URL in any compact srcset reaches the export.

2. data-src and data-srcset attributes are not scanned

The same loop scans src and srcset, but skips data-src / data-srcset. Lazy-loading is widespread — Easy LQP, Lazysizes, BLazy, native lazyload polyfills, and a number of Drupal contrib modules use the same convention: real image URLs live in
data-src / data-srcset with a placeholder in the canonical src. Tome picks up the placeholder and never sees the actual image URLs. Image-style derivatives referenced only via lazy-load never enter the static export, and the deployed site has broken images for
anything below the fold.

Steps to reproduce

Render any page with (a) a Drupal responsive image style emitting compact srcset values, and (b) lazy-loaded images using data-src / data-srcset. Run drush tome:static. Only one image variant per srcset is exported, and lazy-loaded image URLs are missing
entirely.

Proposed resolution

Extract a parseSrcset() helper that splits the attribute value on comma first and pulls the URL from each candidate as the first whitespace-separated token — what the HTML spec actually defines for srcset parsing. Use the helper for both srcset and data-srcset.
Also pick up data-src as a single-URL attribute alongside src.

Issue fork tome-3591175

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

shiraz dindar created an issue.