File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -188,8 +188,27 @@ def _get_fragment(raw: str) -> str:
188188_DOC_HTML_TO_DOCNAME = {v : v .replace ('.html' , '' ) for v in _DOC_MD_TO_HTML .values ()}
189189
190190
191+ def _rewrite_locale_asset_paths (doctree : nodes .document ) -> None :
192+ """Rewrite image paths so they work in both normal and gettext (locale) builds.
193+
194+ In locale builds, content comes from .po files; relative paths like ../images/...
195+ are then resolved from the document dir (source/), so ../images points to
196+ sphinx-docs/images instead of project root. Fix by rewriting ../images/ to
197+ ../../images/ (relative to source/ = project root images/).
198+ """
199+ prefix = '../images/'
200+ replacement = '../../images/'
201+ for node in doctree .traverse (nodes .image ):
202+ uri = node .get ('uri' , '' )
203+ if uri .startswith (prefix ):
204+ node ['uri' ] = replacement + uri [len (prefix ):]
205+
206+
191207def _rewrite_doc_md_links (app , doctree , docname ):
192208 """Rewrite links to docs/*.md so they point to the built .html (works in both .md and Sphinx)."""
209+ # Fix image paths for locale builds (content from .po resolves paths from source/)
210+ _rewrite_locale_asset_paths (doctree )
211+
193212 builder = getattr (app , 'builder' , None )
194213 get_uri = getattr (builder , 'get_relative_uri' , None ) if builder else None
195214
You can’t perform that action at this time.
0 commit comments