executablebooks / sphinx-copybutton

Add a "copy" button to code blocks in Sphinx
https://sphinx-copybutton.readthedocs.io/en/latest/
MIT License
240 stars 49 forks source link

URL to copy-button.svg is incorrect because DOCUMENTATION_OPTIONS.URL_ROOT is undefined #214

Open rhertzog opened 5 months ago

rhertzog commented 5 months ago

Describe the bug

When I build some documentation with sphinx-copybutton 0.4.0 and Sphinx 7.2.6 with a simple "make html" invocation, and when I open the webpage in my local browser, I don't get to see the copy-button.svg icon, instead I see the associated alt text.

When I lookup the HTML, the path to the image is undefined_static/copy-button.svg which obviously doesn't work.

This is a consequence that the generated HTML doesn't define the DOCUMENTATION_OPTIONS.URL_ROOT variable. I have this in head:

<script src="../../../_static/documentation_options.js?v=7f41d439"></script>

And documentation_options.js looks like this:

const DOCUMENTATION_OPTIONS = {
    VERSION: '',
    LANGUAGE: 'en',
    COLLAPSE_INDEX: false,
    BUILDER: 'html',
    FILE_SUFFIX: '.html',
    LINK_SUFFIX: '.html',
    HAS_SOURCE: false,
    SOURCELINK_SUFFIX: '.txt',
    NAVIGATION_WITH_KEYS: false,
    SHOW_SEARCH_SUMMARY: true,
    ENABLE_SEARCH_SHORTCUTS: true,
};

Reproduce the bug

make html
firefox _build/html/index.html

I'm not quite sure what's responsible of generating this URL_ROOT variable... but it looks like that Sphinx is not doing it automatically, maybe some other extensions needs to be enabled? In my doc, the configuration is pretty minimal:

# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
    'sphinx.ext.todo',
    'sphinx_copybutton',
]
todo_include_todos = True

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store',
                    '**/_template.rst']

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = []

html_copy_source = False

# Disable Python highlighting for literal blocks
highlight_language = "none"

List your environment

Debian unstable with python3-sphinx 7.2.6-3 and python3-sphinx-copybutton 0.4.0-4. The documentation uses the alabaster theme version 0.7.12-1.

welcome[bot] commented 5 months ago

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

rhertzog commented 5 months ago

It looks like a breaking change in Sphinx 7.2.x: https://github.com/sphinx-doc/sphinx/commit/8e730ae303ae686705ea12f44ef11da926a87cf5 https://github.com/sphinx-doc/sphinx/issues/11608#issuecomment-1684410476

Vincat commented 3 weeks ago

Hi It looks like I have the same problem. Being new to this sort of stuff, has this been/being fixed. Is there something I can do?