[DISCREPANCY] Asset paths are incorrectly translated
Describe the discrepancy Image asset paths are incorrectly translated to a path relative to the Sphinx root instead of relative to the document the reference occurs in. This is because the Sphinx asset collector modifies the URI to be relative to the root and not the document here.
Absolute asset references are also modified such that /a/b/c.png drops the leading slash.
Other builders like the HTML builder copy the assets to a common directory and adjust links as necessary so they still point to the directory regardless of depth. It looks like this builder just replaces with uri.
The easiest fix would be using original_uri instead. That at least makes it possible for users to copy all assets into their same location in the build directory and have working files.
The optimal solution would either gather the assets into a common directory and adjust links to point to that one common directory (like the HTML builder). Or use original_uri and copy assets into the build directory in the same structure as the source so the relative references are still valid.
To Reproduce Steps to reproduce the behavior:
- Create a
docs/dir/page.rstfile with the following contents.. image:: ../assets/img.png .. image:: /assets/img.png - Create a
docs/assets/img.pngfile (it doesn't have to be a valid image, you can just touch the file) - Build with sphinx
Expected output The output file should be


Environment (please complete the following information):
- OS: Linux Pop OS
- Version 22.04
Additional context
The actual output is the same even if you move the page file deeper and add appropriate ../ to the path.


Thanks for opening this issue.
Copying the assets is a must, I agree. To prevent breaking existing builds, I might initially introduce a parameter to opt into this behaviour.
Regarding the relative vs absolute issue, the HTML builder ignores absolute paths by removing the leading /. This builder is aligned with this behaviour.