You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.
The image() function generates the RST directive which includes the :target: attribute. Since Sphinx copies all images to /_images, any images in subfolders will have a broken link using :target: which which include the subdirectory path. Since the :target: attribute still references the relative path based on the source directory and not the /_images directory, clicking the links generates a 404.
Example Output of Broken href
You can see the difference in paths. the href path will not exists. In source, these images are in a subdirectory.
<aclass="reference external image-reference" href="../_images/curl_jokes_json.gif"><imgalt="cURL with JSON" src="../../_images/curl_jokes_json.gif" /></a>
Possible Fix
Since it seems that Sphinx always copies all images to the /_images folder, modifying the method like this could work:
defimage(self, src, title, text):
"""Rendering a image with title and text. :param src: source link of the image. :param title: title text of the image. :param text: alt text of the image. """image_name=os.path.basename(src)
target=f"/_images/{image_name}"# rst does not support title option# and I couldn't find title attribute in HTML standardreturn'\n'.join([
'',
'.. image:: {}'.format(src),
' :target: {}'.format(target),
' :alt: {}'.format(text),
'',
])
Essentially, parsing the filename from the original source and generating target based on where we know sphinx is going to put the images.
The text was updated successfully, but these errors were encountered:
Had a similar problem. I'm cloning a gitlab wiki (which is in markdown) into my sphinx project via .gitlab_ci.yml
Wanted to have Lightbox feature from: sphinxcontrib-images.
Didn't work as it only parses .rst images. So I found m2r. Still didn't work - because of target.
Removed it - fine.
I actually don't wanna have target at all - becaus click opens the lightbox. Maybe make it configurable?
But currently I'm converting via shell - so conf.py option wouldn't help. Have markdown extension installed (currently) - and you can install markdown and m2r (which does make some sense ...).
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Problem
The image() function generates the RST directive which includes the :target: attribute. Since Sphinx copies all images to /_images, any images in subfolders will have a broken link using :target: which which include the subdirectory path. Since the :target: attribute still references the relative path based on the source directory and not the /_images directory, clicking the links generates a 404.
Example Output of Broken href
You can see the difference in paths. the href path will not exists. In source, these images are in a subdirectory.
Possible Fix
Since it seems that Sphinx always copies all images to the /_images folder, modifying the method like this could work:
Essentially, parsing the filename from the original source and generating target based on where we know sphinx is going to put the images.
The text was updated successfully, but these errors were encountered: