Skip to content

matplotlib.sphinxext.plot_directive generates incorrect links when using dirhtml builder #13858

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

Closed
glenfletcher opened this issue Apr 3, 2019 · 3 comments

Comments

@glenfletcher
Copy link

When using the dirhtml builder in sphinx with the .. plot:: directive, the generated links are relative to the source file tree not the output, i.e. the source file name become a directory containing index.html, however the relative path generated is based on the location of the source file

dest_dir_link = os.path.join(relpath(setup.confdir, rst_dir),

I fixed this locally using the the following hack, however I don't think this is the appropriate solution there should be some way to make the directive use the output path not the input path, which would remove the need for a hack solution. Hence I'm posting this as a issue rather than a patch.

    if setup.app.builder.name == 'dirhtml':
        subdir = os.path.basename(os.path.splitext(rst_file)[0])
        dest_dir_link = os.path.join(relpath(setup.confdir, os.path.join(rst_dir, subdir)),
                                     source_rel_dir).replace(os.path.sep, '/')
    else:
        dest_dir_link = os.path.join(relpath(setup.confdir, rst_dir),
                                     source_rel_dir).replace(os.path.sep, '/')
@anntzer
Copy link
Contributor

anntzer commented Apr 3, 2019

Related to #12456, perhaps(?).

@MikhailRyazanov
Copy link
Contributor

PR #24205 seems to solve this issue in a more robust way. If anybody is still interested, please test it.

@QuLogic
Copy link
Member

QuLogic commented Nov 24, 2022

I confirmed that this works now by copying the test tinypages/some_plots.rst into a subdirectory and building before and after the above PR. The download links are now working, and not using broken relative paths.

@QuLogic QuLogic closed this as completed Nov 24, 2022
@QuLogic QuLogic added this to the v3.7.0 milestone Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants