Skip to content

Allow specifying custom check icon svg #203

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions docs/contribute/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pip install -e /path/to/sphinx_copybutton

The package is tested for three things (see `.github/workflows/integration.yml`):

## code style
## Code style

To adhere to this code style install the package with [pre-commit](https://pre-commit.com/):

Expand Down Expand Up @@ -59,7 +59,7 @@ NodeJS >= 12 is required
Install the package:

```console
$ pip install .
$ pip install .[rtd]
```

Then run the docs build:
Expand Down
4 changes: 2 additions & 2 deletions docs/use.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ but if one of the lines to be copied contains the defined delimiter (here: `EOT`
then all following lines will be copied literally until the next delimiter is
encountered in a line.

## Change the copy button image
## Change the icons

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

Expand Down Expand Up @@ -266,7 +266,7 @@ For example, if you wanted to use a **clipboard icon** instead of the default co
"""
```

When you re-build your documentation, you should see this new icon in your copy buttons.
When you re-build your documentation, you should see this new icon in your copy buttons. Similarly, you could change the check icon's image by setting the `checkbutton_image_svg` variable in your `conf.py`. Note that `checkbutton_image_svg` and `copybutton_image_svg` expect the full SVG content, **NOT** a path to an SVG file.

## Add or remove copy buttons to any element with a CSS selector

Expand Down
2 changes: 2 additions & 0 deletions sphinx_copybutton/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def add_to_context(app, config):
config.copybutton_image_svg = path.read_text()

config.html_context.update({"copybutton_image_svg": config.copybutton_image_svg})
config.html_context.update({"checkbutton_image_svg": config.checkbutton_image_svg})
config.html_context.update({"copybutton_selector": config.copybutton_selector})
config.html_context.update(
{
Expand Down Expand Up @@ -80,6 +81,7 @@ def setup(app):
app.add_config_value("copybutton_line_continuation_character", "", "html")
app.add_config_value("copybutton_here_doc_delimiter", "", "html")
app.add_config_value("copybutton_image_svg", "", "html")
app.add_config_value("checkbutton_image_svg", "", "html")
app.add_config_value("copybutton_selector", "div.highlight pre", "html")
app.add_config_value("copybutton_exclude", ".linenos", "html")

Expand Down
10 changes: 7 additions & 3 deletions sphinx_copybutton/_static/copybutton.js_t
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,19 @@ if (doc_url_root == '#') {
}

/**
* SVG files for our copy buttons
* SVG file contents for our icons, if the user specified their own SVG use that, otherwise use the default.
Note that value of `checkbutton_image_svg` or `copybutton_image_svg` is the full SVG content, NOT a path to an SVG file.
*/
let iconCheck = `<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-check" width="44" height="44" viewBox="0 0 24 24" stroke-width="2" stroke="#22863a" fill="none" stroke-linecap="round" stroke-linejoin="round">

let iconCheck = `{{ checkbutton_image_svg }}`;
if (!iconCheck) {
iconCheck = `<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-check" width="44" height="44" viewBox="0 0 24 24" stroke-width="2" stroke="#22863a" fill="none" stroke-linecap="round" stroke-linejoin="round">
<title>${messages[locale]['copy_success']}</title>
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
<path d="M5 12l5 5l10 -10" />
</svg>`
}

// If the user specified their own SVG use that, otherwise use the default
let iconCopy = `{{ copybutton_image_svg }}`;
if (!iconCopy) {
iconCopy = `<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copy" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round">
Expand Down