Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
# copybutton_only_copy_prompt_lines = False
# copybutton_remove_prompts = False
# copybutton_image_path = "test/TEST_COPYBUTTON.png"
# copybutton_selector = "div"


# -- Options for HTMLHelp output ---------------------------------------------

Expand Down
23 changes: 22 additions & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,35 @@ strip the prompts), use the following configuration in ``conf.py``:
copybutton_remove_prompts = False

Use a different copy button image
---------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To use a different image for your copy buttons, do the following:

1. Place the image in the ``_static/`` folder of your site.
2. Set the ``copybutton_image_path`` variable in your ``conf.py`` to be the
path to your image file, **relative to** ``_static/``.


Configure the CSS selector used to add copy buttons
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

By default, ``sphinx-copybutton`` will add a copy button to all elements
that match the following selection:

.. code-block:: css

div.highlight pre

To change this selector, use the following configuration in ``conf.py``:

.. code-block:: python

copybutton_selector = "your.selector"

In this case, all elements that match ``your.selector`` will have a copy button
added to them.


Development
===========

Expand Down
2 changes: 2 additions & 0 deletions sphinx_copybutton/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def add_to_context(app, config):
config.html_context.update({'copybutton_only_copy_prompt_lines': config.copybutton_only_copy_prompt_lines})
config.html_context.update({'copybutton_remove_prompts': config.copybutton_remove_prompts})
config.html_context.update({'copybutton_image_path': config.copybutton_image_path})
config.html_context.update({'copybutton_selector': config.copybutton_selector})

def setup(app):
print('Adding copy buttons to code blocks...')
Expand All @@ -24,6 +25,7 @@ def setup(app):
app.add_config_value("copybutton_only_copy_prompt_lines", True, "html")
app.add_config_value("copybutton_remove_prompts", True, "html")
app.add_config_value("copybutton_image_path", "copy-button.svg", "html")
app.add_config_value("copybutton_selector", "div.highlight pre", "html")

# Add configuration value to the template
app.connect("config-inited", add_to_context)
Expand Down
2 changes: 1 addition & 1 deletion sphinx_copybutton/_static/copybutton.js_t
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const addCopyButtonToCodeCells = () => {
}

// Add copybuttons to all of our code cells
const codeCells = document.querySelectorAll('div.highlight pre')
const codeCells = document.querySelectorAll('{{ copybutton_selector }}')
codeCells.forEach((codeCell, index) => {
const id = codeCellId(index)
codeCell.setAttribute('id', id)
Expand Down