diff --git a/docs/contribute/index.md b/docs/contribute/index.md index 7fe7b15..c92bbab 100644 --- a/docs/contribute/index.md +++ b/docs/contribute/index.md @@ -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/): @@ -59,7 +59,7 @@ NodeJS >= 12 is required Install the package: ```console -$ pip install . +$ pip install .[rtd] ``` Then run the docs build: diff --git a/docs/use.md b/docs/use.md index 2709c5d..c3b8a0c 100644 --- a/docs/use.md +++ b/docs/use.md @@ -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: @@ -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 diff --git a/sphinx_copybutton/__init__.py b/sphinx_copybutton/__init__.py index d0fd38a..4a2dd68 100644 --- a/sphinx_copybutton/__init__.py +++ b/sphinx_copybutton/__init__.py @@ -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( { @@ -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") diff --git a/sphinx_copybutton/_static/copybutton.js_t b/sphinx_copybutton/_static/copybutton.js_t index ec91f20..763db4d 100644 --- a/sphinx_copybutton/_static/copybutton.js_t +++ b/sphinx_copybutton/_static/copybutton.js_t @@ -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 = ` + +let iconCheck = `{{ checkbutton_image_svg }}`; +if (!iconCheck) { + iconCheck = ` ${messages[locale]['copy_success']} ` +} -// If the user specified their own SVG use that, otherwise use the default let iconCopy = `{{ copybutton_image_svg }}`; if (!iconCopy) { iconCopy = `