{"id":1720,"library":"sphinx-copybutton","title":"Sphinx Copybutton","description":"sphinx-copybutton is a Sphinx extension that adds a 'copy' button to each of your code cells in Sphinx documentation. It is currently at version 0.5.2, actively maintained, and releases generally align with bug fixes, minor enhancements, or updates to stay compatible with Sphinx itself.","status":"active","version":"0.5.2","language":"en","source_language":"en","source_url":"https://github.com/executablebooks/sphinx-copybutton","tags":["sphinx","documentation","copy","code","frontend"],"install":[{"cmd":"pip install sphinx-copybutton","lang":"bash","label":"Install `sphinx-copybutton`"}],"dependencies":[{"reason":"Required to build documentation. sphinx-copybutton is a Sphinx extension.","package":"Sphinx","optional":false}],"imports":[{"note":"Sphinx extensions are activated by adding their string name to the 'extensions' list in your Sphinx project's conf.py file, not via Python import statements.","symbol":"sphinx_copybutton","correct":"# In conf.py\nextensions = [\n    'sphinx_copybutton'\n]"}],"quickstart":{"code":"# 1. Install the package:\n# pip install sphinx-copybutton\n\n# 2. Add 'sphinx_copybutton' to your conf.py extensions list:\n\n# conf.py\nimport os\nimport sys\n\nproject = 'My Project'\ncopyright = '2023, Author'\n\nextensions = [\n    'sphinx.ext.autodoc',\n    'sphinx_copybutton'\n]\n\n# Optional: Configure prompt text for copy button (example)\ncopybutton_prompt_text = \"$ \"\ncopybutton_prompt_is_regexp = False","lang":"python","description":"To enable sphinx-copybutton, first install it using pip. Then, add 'sphinx_copybutton' to the `extensions` list within your Sphinx project's `conf.py` file. You can optionally configure its behavior, for example, by setting `copybutton_prompt_text` to exclude shell prompts from being copied."},"warnings":[{"fix":"Review your `copybutton_prompt_text` configuration. If you were double-escaping backslashes, you now only need a single escape (e.g., `\"\\\\$ \"` became `\"\\$ \"`). Refer to the v0.3.0 release notes.","message":"In v0.3.0, the handling of `copybutton_prompt_text` regex strings changed to use raw string formatting. This required users to update their `copybutton_prompt_text` string to remove previous 'double escaping'.","severity":"breaking","affected_versions":">=0.3.0"},{"fix":"Update any custom CSS targeting the copy button to reflect the new SVG-based structure. You may need to target the `svg` element or its parent container directly. Inspect the generated HTML to identify the correct selectors.","message":"Starting with v0.5.0, the copy button design was updated to match GitHub's behavior, and the SVG icon is directly inserted into the HTML instead of being linked via an `<img>` tag. This can break custom CSS that targeted the `<img>` element for styling the button.","severity":"gotcha","affected_versions":">=0.5.0"},{"fix":"If you use code blocks with `... prompt` directives (which often apply the `.gp` class) and find prompts are now copied, explicitly configure `copybutton_prompt_text` with a regular expression (e.g., `^\\$ `) to exclude them, ensuring `copybutton_prompt_is_regexp = True`.","message":"In v0.5.2, a bug fix reversed the default exclusion of the `.gp` class from copy button processing. This change might unintentionally include prompt text in copied code for users who previously relied on `.gp` to be excluded by default.","severity":"gotcha","affected_versions":">=0.5.2"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}