Skip to content

fix(build): copy images referenced only by gallery-src - #2273

Merged
martyanovandrey merged 1 commit into
masterfrom
fix/gallery-src-assets
Sep 17, 2026
Merged

martyanovandrey merged 1 commit into
masterfrom
fix/gallery-src-assets

Conversation

@martyanovandrey

Copy link
Copy Markdown
Contributor

Problem

An image can point to a heavier version of itself with the gallery-src option:

![](../../_images/mountain-tiny.jpg){gallery-src=../../_images/mountain.jpg}

The gallery version is never rendered inline, and asset collection only looked at link destinations, so mountain.jpg was never registered as an asset.

In html output this went unnoticed: output-html copies the whole input directory. In md output, which copies only collected assets, the file never reached the output - and the viewer, which serves the md build, answered 404 when the gallery was expanded.

Reproduced on the platform docs themselves (ru/syntax/media.md in diplodoc-platform/docs, the page that documents gallery-src):

5.57.3   ->  _images/mountain-tiny.jpg, ru/_images/mountain.jpg, en/_images/mountain.jpg
this PR  ->  + _images/mountain.jpg

The missing file matches the 404 seen in production: https://diplodoc.com/docs/docs-assets/diplodoc-platform--docs/rev/<rev>/_images/mountain.jpg.

Fix

  • parseLinkOptions now accepts hyphenated option names, so gallery-src is read as gallerySrc instead of being truncated to a stray src key.
  • findLinksInfo derives an extra image asset from every gallery-src, marked with a new gallery subtype. It shares the location of the image it belongs to, so it is filtered out of code blocks and comments together with it.
  • The new subtype is size-checked (YFM013) like a regular image, but skipped by mergeSvg - inlining it would replace the rendered image with the gallery version.

Notes

Options of reference images (![alt][ref]{width=100}) are not parsed at all today, so gallery-src on them is not collected either. That is a separate pre-existing gap; a test pins the current behaviour so whoever fixes option parsing notices it.

An image can point to a heavier version of itself with the `gallery-src`
option: `![](small.png){gallery-src=big.png}`. The gallery version is never
rendered inline, and asset collection only looked at link destinations, so
`big.png` was not registered as an asset.

In html output that went unnoticed - it copies the whole input directory.
In md output, which copies only collected assets, the file never reached
the output, and the viewer opened a missing file from S3 when the gallery
was expanded.

Collect `gallery-src` as a separate image asset with the `gallery` subtype,
so it is copied and size-checked like any other image, but is not inlined
by `mergeSvg` (it shares its location with the image it belongs to).

Options of reference images (`![alt][ref]{...}`) are still not parsed at
all, so `gallery-src` on them is not collected either.
@martyanovandrey
martyanovandrey requested review from Yurok868 and stenin-nikita and removed request for a team September 15, 2026 16:30
@sonarqubecloud

Copy link
Copy Markdown

@martyanovandrey
martyanovandrey merged commit 6b40188 into master Sep 17, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants