From ec95efa6f25cd41dfd7f7994e3d2dd50e26f1759 Mon Sep 17 00:00:00 2001 From: stan Date: Fri, 24 Feb 2023 21:22:42 -0500 Subject: [PATCH 1/3] Add change --- sphinx_copybutton/__init__.py | 3 +++ sphinx_copybutton/_static/copybutton.js_t | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/sphinx_copybutton/__init__.py b/sphinx_copybutton/__init__.py index d0fd38a..4a2b5c7 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,8 @@ 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("c", "", "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..6818b04 100644 --- a/sphinx_copybutton/_static/copybutton.js_t +++ b/sphinx_copybutton/_static/copybutton.js_t @@ -56,13 +56,17 @@ if (doc_url_root == '#') { } /** - * SVG files for our copy buttons + * SVG files for our icons, if the user specified their own SVG use that, otherwise use the default */ -let iconCheck = ` + +let iconCheck = `{{ checkbutton_image_svg }}`; +if (!iconCheck) { + iconCopy = ` ${messages[locale]['copy_success']} ` +} // If the user specified their own SVG use that, otherwise use the default let iconCopy = `{{ copybutton_image_svg }}`; From 3a45f8c183c1a4ca0c1eefa5ba414d26f3104aa2 Mon Sep 17 00:00:00 2001 From: stan Date: Sat, 25 Feb 2023 23:40:53 -0500 Subject: [PATCH 2/3] Address comments --- docs/use.md | 4 ++-- sphinx_copybutton/__init__.py | 1 - sphinx_copybutton/_static/copybutton.js_t | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) 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 4a2b5c7..4a2dd68 100644 --- a/sphinx_copybutton/__init__.py +++ b/sphinx_copybutton/__init__.py @@ -82,7 +82,6 @@ def setup(app): 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("c", "", "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 6818b04..40dcb06 100644 --- a/sphinx_copybutton/_static/copybutton.js_t +++ b/sphinx_copybutton/_static/copybutton.js_t @@ -56,7 +56,8 @@ if (doc_url_root == '#') { } /** - * SVG files for our icons, if the user specified their own SVG use that, otherwise use the default + * 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 = `{{ checkbutton_image_svg }}`; @@ -68,7 +69,6 @@ if (!iconCheck) { ` } -// If the user specified their own SVG use that, otherwise use the default let iconCopy = `{{ copybutton_image_svg }}`; if (!iconCopy) { iconCopy = ` From 31c61d2368ce95ae53e0c6fb0639a170feab1bf4 Mon Sep 17 00:00:00 2001 From: Sealphie Date: Sun, 26 Feb 2023 12:55:59 -0500 Subject: [PATCH 3/3] Fix js --- docs/contribute/index.md | 4 ++-- sphinx_copybutton/_static/copybutton.js_t | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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/sphinx_copybutton/_static/copybutton.js_t b/sphinx_copybutton/_static/copybutton.js_t index 40dcb06..763db4d 100644 --- a/sphinx_copybutton/_static/copybutton.js_t +++ b/sphinx_copybutton/_static/copybutton.js_t @@ -62,7 +62,7 @@ if (doc_url_root == '#') { let iconCheck = `{{ checkbutton_image_svg }}`; if (!iconCheck) { - iconCopy = ` + iconCheck = ` ${messages[locale]['copy_success']}