Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support externally hosted images (v2) #705

Merged
merged 1 commit into from
Feb 13, 2022
Merged

support externally hosted images (v2) #705

merged 1 commit into from
Feb 13, 2022

Conversation

jdknight
Copy link
Contributor

Observed an issue when attempting to process tinyxml documentation. After generating XML documentation from tinyxml, processing it through breathe would result in the following warning:

sphinx.errors.SphinxWarning: ...\tinyxml.rst::image file not readable: xml/tinyxml/https:/github.com/leethomason/tinyxml2/actions/workflows/test.yml/badge.svg

The project prefix xml/tinyxml/ had been injected into the URI of the image. This commit tries to help mitigate using an absolute path building for external images by checking if the URI defines a URL schema (using implementation from Sphinx's utility class). If a URL schema is detected, assume the source is an external image and just passthrough the value to the generate image node's uri value. Otherwise, default to building a Sphinx project's absolute path to the image.

  • Crudely tested with tinyxml (includes external images) and oglft's documentation (with internal images).
  • Sphinx's url_re call should be available in oldest supported Sphinx revision listed (v2.3.1).

Copy link
Collaborator

@vermeeren vermeeren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdknight Besides specific comment, this makes sense to me. Thanks for the v2!

path_to_image = self.project_info.sphinx_abs_path_to_file(node.name)
path_to_image = node.name
if not url_re.match(path_to_image):
path_to_image = self.project_info.relative_path_to_xml_file(path_to_image)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdknight It used to call abs path function, but now calls rel path to xml file function. At a glance, this appears to be a mistake, can you confirm?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot seem to recall why the change (and it's odd that nothing about it was mentioned in the commit; my apologies).

I do not know if this is a mistake though. Looking at the implementation, sphinx_abs_path_to_file is the same as relative_path_to_xml_file, but with an injected path separator at the start (so a srcdir-rooted abspath?). It appears off to me to build a nodes.images with a uri with a leading path seperator -- unknown what that means for Windows instances and how various plugins interpret the root location of uri. I know a Sphinx extension I help maintain, we've observed various plugins generating uri entries with relative paths to the working directory, relative paths on the source/environment directory and absolute paths on the system. By injecting the / on Linux systems, one may (incorrectly) interpret it is as an absolute path to the entire system (which would not work in this case). I am not sure off hand what is the "right" value for a uri entry; I have not seen any specifics in docutils/Sphinx on what is the "right" way to format these uri attributes.

That all being said, I have no problems if we adjust this commit back to using sphinx_abs_path_to_file to just focus on resolving the external hosted URI entries. If there is a desire to use relative_path_to_xml_file, I could go back and re-test against tinyxml and oglft's documentations against various builders and report back.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vermeeren, I have updated the pull request to fall back to the original sphinx_abs_path_to_file implementation. This is have this pull request focus on URL-provided images.

Any attempts to switch from sphinx_abs_path_to_file to relative_path_to_xml_file could be done in a separate pull request (which can outline in more details on the specific error cases; if any).

@vermeeren vermeeren self-assigned this Sep 18, 2021
@vermeeren vermeeren added code Source code enhancement Improvements, additions (also cosmetics) labels Sep 18, 2021
Copy link
Collaborator

@michaeljones michaeljones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good idea to me. Thanks for catching it.

@michaeljones
Copy link
Collaborator

@jdknight - is this for tinyxml 1 or 2? Is it the copy of tinyxml we have in the breathe repo? I can't see any image links in there. It still seems like a reasonable change but I'm not sure what example you're working with and I'd like to be able to test it myself.

@jdknight
Copy link
Contributor Author

@michaeljones, this is using tinyxml2.

I believe for this project, the images are found without a readme.md file which is included in their Doxygen configuration.

An example of this output can be found here.

When building an image node, check to see if the URI defines a URL
schema. If so, assume the source is an external image and just
passthrough the value to the generate image node's uri value. Otherwise,
default to building a Sphinx project's absolute path to the image.

Signed-off-by: James Knight <james.d.knight@live.com>
Copy link
Collaborator

@vermeeren vermeeren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdknight Apologies that I took so long to get back to you for such a simple and clean patch. Will merge it now, thanks!

michaeljones pushed a commit that referenced this pull request Feb 13, 2022
@michaeljones michaeljones merged commit 6e8fff1 into breathe-doc:master Feb 13, 2022
@jdknight jdknight deleted the support-external-images branch February 14, 2022 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code Source code enhancement Improvements, additions (also cosmetics)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants