talira

sphinx-copybutton

Add a copy button to code blocks in Sphinx docs

open sourceMITfree

sphinx-copybutton is a small Sphinx extension that adds a copy button to the right of every code block in a built documentation site, so readers can copy the code with one click. It's enabled by adding sphinx_copybutton to the extensions in conf.py, and its look can be changed by overriding its CSS. The button itself is powered by clipboard.js.

Ways to install

Package managers

Problems it solves

  • add copy-to-clipboard buttons to code blocks in my Sphinx docs
  • let readers copy code snippets from Read the Docs pages
  • add a copy button to Sphinx code examples

Features

  • copy button on every code block
  • one line in conf.py to enable
  • styling through overridable CSS
  • installs from PyPI or conda-forge

Alternatives

The same job

These do what sphinx-copybutton does.

  1. Sphinx Create intelligent and beautiful documentation with ease
  2. nbsphinx Sphinx extension that renders Jupyter notebooks in HTML and LaTeX documentation
  3. sphinx-autodoc-typehints Render Python type hints in Sphinx autodoc documentation
  4. MyST-Parser Write Sphinx and Docutils documentation in MyST Markdown
  5. numpydoc Sphinx extension for NumPy-style docstrings
  6. starlight-llm-actions Starlight plugin: Page Actions dropdown with Copy/View/PDF and Open-in-LLM buttons

Compare sphinx-copybutton with the top 3