Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package python-sphinxcontrib-copybutton for openSUSE:Factory checked in at 2022-12-06 14:22:51 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-sphinxcontrib-copybutton (Old) and /work/SRC/openSUSE:Factory/.python-sphinxcontrib-copybutton.new.1835 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-sphinxcontrib-copybutton" Tue Dec 6 14:22:51 2022 rev:2 rq:1040266 version:0.5.1 Changes: -------- --- /work/SRC/openSUSE:Factory/python-sphinxcontrib-copybutton/python-sphinxcontrib-copybutton.changes 2022-11-07 13:51:42.707808410 +0100 +++ /work/SRC/openSUSE:Factory/.python-sphinxcontrib-copybutton.new.1835/python-sphinxcontrib-copybutton.changes 2022-12-06 14:22:54.369418845 +0100 @@ -1,0 +2,13 @@ +Thu Dec 1 09:15:57 UTC 2022 - Michael Vetter <mvet...@suse.com> + +- Update to 0.5.1: + * ENH: Unselectable text is now also not highlighted when you + manually highlight a code cell. Exclude unselectable text + from being copied (update) #178 + * ENH: After copying, the copybutton will disappear before the + icon changes back if you are no longer hovering on the code + cell. FIX: Make copybutton remain for a second during + success #176 + * MAINT: Add support for Python 3.10 #174 + +------------------------------------------------------------------- Old: ---- sphinx-copybutton-0.5.0.tar.gz New: ---- sphinx-copybutton-0.5.1.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-sphinxcontrib-copybutton.spec ++++++ --- /var/tmp/diff_new_pack.fxF6mK/_old 2022-12-06 14:22:54.909421807 +0100 +++ /var/tmp/diff_new_pack.fxF6mK/_new 2022-12-06 14:22:54.917421851 +0100 @@ -1,5 +1,5 @@ # -# spec file for package python-sphinx-copybutton +# spec file for package python-sphinxcontrib-copybutton # # Copyright (c) 2022 SUSE LLC # @@ -18,25 +18,25 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} Name: python-sphinxcontrib-copybutton -Version: 0.5.0 +Version: 0.5.1 Release: 0 Summary: Add a copy button to each of your code cells License: MIT URL: https://github.com/executablebooks/sphinx-copybutton Source: https://files.pythonhosted.org/packages/source/s/sphinx-copybutton/sphinx-copybutton-%{version}.tar.gz -BuildRequires: python-rpm-macros BuildRequires: %{python_module setuptools} -# SECTION test requirements -BuildRequires: %{python_module Sphinx >= 1.8} -# /SECTION BuildRequires: fdupes +BuildRequires: python-rpm-macros Requires: python-Sphinx >= 1.8 -Suggests: python-pre-commit == 2.12.1 -Suggests: python-sphinx Suggests: python-ipython Suggests: python-myst-nb +Suggests: python-pre-commit = 2.12.1 +Suggests: python-sphinx Suggests: python-sphinx-book-theme BuildArch: noarch +# SECTION test requirements +BuildRequires: %{python_module Sphinx >= 1.8} +# /SECTION %python_subpackages %description ++++++ sphinx-copybutton-0.5.0.tar.gz -> sphinx-copybutton-0.5.1.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/sphinx-copybutton-0.5.0/PKG-INFO new/sphinx-copybutton-0.5.1/PKG-INFO --- old/sphinx-copybutton-0.5.0/PKG-INFO 2022-02-06 04:06:32.772196300 +0100 +++ new/sphinx-copybutton-0.5.1/PKG-INFO 2022-11-15 11:17:11.003572200 +0100 @@ -1,19 +1,18 @@ Metadata-Version: 2.1 Name: sphinx-copybutton -Version: 0.5.0 +Version: 0.5.1 Summary: Add a copy button to each of your code cells. Home-page: https://github.com/executablebooks/sphinx-copybutton Author: Executable Book Project License: MIT License -Platform: UNKNOWN Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 +Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3 :: Only -Requires-Python: >=3.6 +Requires-Python: >=3.7 Description-Content-Type: text/markdown Provides-Extra: code_style Provides-Extra: rtd @@ -75,5 +74,3 @@ ## Acknowledgements Many thanks to the excellent [clipboard.js library](https://clipboardjs.com/) for the lightweight javascript code that powers the copy button! - - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/sphinx-copybutton-0.5.0/docs/conf.py new/sphinx-copybutton-0.5.1/docs/conf.py --- old/sphinx-copybutton-0.5.0/docs/conf.py 2022-02-06 04:06:23.000000000 +0100 +++ new/sphinx-copybutton-0.5.1/docs/conf.py 2022-11-15 11:16:59.000000000 +0100 @@ -37,7 +37,12 @@ # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = ["sphinx_copybutton", "IPython.sphinxext.ipython_directive", "myst_nb"] +extensions = [ + "sphinx_copybutton", + "sphinx_examples", + "IPython.sphinxext.ipython_directive", + "myst_nb", +] # Add any paths that contain templates here, relative to this directory. templates_path = ["_templates"] @@ -81,7 +86,10 @@ # further. For a list of options available for each theme, see the # documentation. # -# html_theme_options = {} +html_theme_options = { + "repository_url": "https://github.com/executablebooks/sphinx-copybutton", + "use_repository_button": True, +} # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, @@ -107,6 +115,8 @@ copybutton_prompt_is_regexp = True copybutton_line_continuation_character = "\\" copybutton_here_doc_delimiter = "EOT" +copybutton_selector = "div:not(.no-copybutton) > div.highlight > pre" + # Switches for testing but shouldn't be activated in the live docs # copybutton_only_copy_prompt_lines = False # copybutton_remove_prompts = False @@ -118,7 +128,6 @@ # <rect x="9" y="3" width="6" height="4" rx="2" /> # </svg> # """ -# copybutton_selector = "div" # -- Options for HTMLHelp output --------------------------------------------- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/sphinx-copybutton-0.5.0/docs/index.md new/sphinx-copybutton-0.5.1/docs/index.md --- old/sphinx-copybutton-0.5.0/docs/index.md 2022-02-06 04:06:23.000000000 +0100 +++ new/sphinx-copybutton-0.5.1/docs/index.md 2022-11-15 11:16:59.000000000 +0100 @@ -61,10 +61,6 @@ ## Install -:::{note} -`sphinx-copybutton` only works on Python >= 3.6 -::: - You can install `sphinx-copybutton` with `pip`: ```bash diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/sphinx-copybutton-0.5.0/docs/reference/example.md new/sphinx-copybutton-0.5.1/docs/reference/example.md --- old/sphinx-copybutton-0.5.0/docs/reference/example.md 2022-02-06 04:06:23.000000000 +0100 +++ new/sphinx-copybutton-0.5.1/docs/reference/example.md 2022-11-15 11:16:59.000000000 +0100 @@ -45,6 +45,22 @@ :language: python ``` +## Tables + +````{list-table} +- * ``` + cell one + ``` + * ``` + cell two + ``` +- * ``` + cell three + ``` + * ``` + cell four + ``` +```` ## MyST Notebook Cells Sphinx Copybutton works with [MyST Notebooks](https://myst-nb.readthedocs.io) as well. See below for the code inputs and outputs: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/sphinx-copybutton-0.5.0/docs/use.md new/sphinx-copybutton-0.5.1/docs/use.md --- old/sphinx-copybutton-0.5.0/docs/use.md 2022-02-06 04:06:23.000000000 +0100 +++ new/sphinx-copybutton-0.5.1/docs/use.md 2022-11-15 11:16:59.000000000 +0100 @@ -268,7 +268,7 @@ When you re-build your documentation, you should see this new icon in your copy buttons. -## Add copy buttons to other elements with a CSS selector +## Add or remove copy buttons to any element with a CSS selector By default, `sphinx-copybutton` will add a copy button to all elements that match the following selection: @@ -280,13 +280,56 @@ To change this selector, use the following configuration in `conf.py`: ```python -copybutton_selector = "your.selector" +copybutton_selector = "div.myselector" ``` -In this case, all elements that match `your.selector` will have a copy button +In this case, all `<div>` elements that have a `myselector` will have a copy button added to them. -## Modify the copy button's CSS +### Remove copybuttons using a CSS selector + +You can prevent copybuttons from being added to code blocks by using [the `:not()` CSS selector](https://developer.mozilla.org/en-US/docs/Web/CSS/:not). + +For example, you can define a copybutton_selector like so: + +```python +copybutton_selector = "div:not(.no-copybutton) > div.highlight > pre" +``` + +Then add a `no-copybutton` to any code blocks you don't want copied: + +````{example} +```{code-block} +:class: no-copybutton +print("This won't have a copy button!") +``` +```` + +### A typical code cell HTML structure in Sphinx + +Using CSS to modify the copy button requires you to know what kind of HTML structure code cells have in your documentation. +The easiest way to determine this is to look at the HTML generated by your Sphinx version. +A code block like this: + +```python +print("hi!") +``` + +roughly results in this HTML: + +```html +<div class="{EXTRA CLASSES} highlight-python notranslate"> + <div class="highlight"> + <pre id="codecell7"> + CODE CELL CONTENT HERE + </pre> + </div> +</div> +``` + +Where `{EXTRA CLASSES}` consists of any extra classes you've added with the `:class:` keyword. + +## Modify the copy button's style with CSS You can style the CSS of the copy button however you'd like by writing your own CSS with your Sphinx build. To do so, first create a custom CSS file and add it to your Sphinx build: @@ -323,3 +366,22 @@ See the [Sphinx documentation on custom CSS for more information](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_static_path). [regex101]: https://regex101.com + + +## Exclude text from being copied + +You may exclude elements matching CSS selectors from being copied by +specifying the `copybutton_exclude` option in ``conf.py``. For +example, a viewer usually doesn't want to copy the line numbers, and +CSS provides a way to exclude this. This option implements that +option for sphinx-copybutton as well. + + +```{code-block} python +copybutton_exclude = '.exclude_me' +``` +By default `.linenos, .gp` are excluded. If you specify the +`copybutton_exclude` option it will replace the default. `.linenos` +is the Sphinx default for line numbers, and `.gp` is Pygments (the +default highlighter of Sphinx) for "prompt", e.g. `$` in a +shell-session. `.gp` is excluded in upstream Sphinx by default. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/sphinx-copybutton-0.5.0/setup.py new/sphinx-copybutton-0.5.1/setup.py --- old/sphinx-copybutton-0.5.0/setup.py 2022-02-06 04:06:23.000000000 +0100 +++ new/sphinx-copybutton-0.5.1/setup.py 2022-11-15 11:16:59.000000000 +0100 @@ -51,13 +51,13 @@ classifiers=[ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3 :: Only", ], - python_requires=">=3.6", + python_requires=">=3.7", install_requires=["sphinx>=1.8"], extras_require={ "code_style": ["pre-commit==2.12.1"], @@ -66,6 +66,7 @@ "ipython", "myst-nb", "sphinx-book-theme", + "sphinx-examples", ], }, ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/sphinx-copybutton-0.5.0/sphinx_copybutton/__init__.py new/sphinx-copybutton-0.5.1/sphinx_copybutton/__init__.py --- old/sphinx-copybutton-0.5.0/sphinx_copybutton/__init__.py 2022-02-06 04:06:23.000000000 +0100 +++ new/sphinx-copybutton-0.5.1/sphinx_copybutton/__init__.py 2022-11-15 11:16:59.000000000 +0100 @@ -2,7 +2,7 @@ from pathlib import Path from sphinx.util import logging -__version__ = "0.5.0" +__version__ = "0.5.1" logger = logging.getLogger(__name__) @@ -62,6 +62,7 @@ .replace("export function", "function") } ) + config.html_context.update({"copybutton_exclude": config.copybutton_exclude}) def setup(app): @@ -80,6 +81,7 @@ app.add_config_value("copybutton_here_doc_delimiter", "", "html") app.add_config_value("copybutton_image_svg", "", "html") app.add_config_value("copybutton_selector", "div.highlight pre", "html") + app.add_config_value("copybutton_exclude", ".linenos, .gp", "html") # DEPRECATE THIS AFTER THE NEXT RELEASE app.add_config_value("copybutton_image_path", "", "html") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/sphinx-copybutton-0.5.0/sphinx_copybutton/_static/copybutton.css new/sphinx-copybutton-0.5.1/sphinx_copybutton/_static/copybutton.css --- old/sphinx-copybutton-0.5.0/sphinx_copybutton/_static/copybutton.css 2022-02-06 04:06:23.000000000 +0100 +++ new/sphinx-copybutton-0.5.1/sphinx_copybutton/_static/copybutton.css 2022-11-15 11:16:59.000000000 +0100 @@ -35,7 +35,8 @@ position: relative; } -.highlight:hover button.copybtn { +/* Show the copybutton */ +.highlight:hover button.copybtn, button.copybtn.success { opacity: 1; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/sphinx-copybutton-0.5.0/sphinx_copybutton/_static/copybutton.js_t new/sphinx-copybutton-0.5.1/sphinx_copybutton/_static/copybutton.js_t --- old/sphinx-copybutton-0.5.0/sphinx_copybutton/_static/copybutton.js_t 2022-02-06 04:06:23.000000000 +0100 +++ new/sphinx-copybutton-0.5.1/sphinx_copybutton/_static/copybutton.js_t 2022-11-15 11:16:59.000000000 +0100 @@ -102,18 +102,25 @@ } } -// Changes tooltip text for two seconds, then changes it back +// Changes tooltip text for a moment, then changes it back +// We want the timeout of our `success` class to be a bit shorter than the +// tooltip and icon change, so that we can hide the icon before changing back. +var timeoutIcon = 2000; +var timeoutSuccessClass = 1500; + const temporarilyChangeTooltip = (el, oldText, newText) => { el.setAttribute('data-tooltip', newText) el.classList.add('success') - setTimeout(() => el.setAttribute('data-tooltip', oldText), 2000) - setTimeout(() => el.classList.remove('success'), 2000) + // Remove success a little bit sooner than we change the tooltip + // So that we can use CSS to hide the copybutton first + setTimeout(() => el.classList.remove('success'), timeoutSuccessClass) + setTimeout(() => el.setAttribute('data-tooltip', oldText), timeoutIcon) } // Changes the copy button icon for two seconds, then changes it back const temporarilyChangeIcon = (el) => { el.innerHTML = iconCheck; - setTimeout(() => {el.innerHTML = iconCopy}, 2000) + setTimeout(() => {el.innerHTML = iconCopy}, timeoutIcon) } const addCopyButtonToCodeCells = () => { @@ -125,7 +132,8 @@ } // Add copybuttons to all of our code cells - const codeCells = document.querySelectorAll('{{ copybutton_selector }}') + const COPYBUTTON_SELECTOR = '{{ copybutton_selector }}'; + const codeCells = document.querySelectorAll(COPYBUTTON_SELECTOR) codeCells.forEach((codeCell, index) => { const id = codeCellId(index) codeCell.setAttribute('id', id) @@ -141,7 +149,12 @@ var copyTargetText = (trigger) => { var target = document.querySelector(trigger.attributes['data-clipboard-target'].value); - return formatCopyText(target.innerText, {{ "{!r}".format(copybutton_prompt_text) }}, {{ copybutton_prompt_is_regexp | lower }}, {{ copybutton_only_copy_prompt_lines | lower }}, {{ copybutton_remove_prompts | lower }}, {{ copybutton_copy_empty_lines | lower }}, {{ "{!r}".format(copybutton_line_continuation_character) }}, {{ "{!r}".format(copybutton_here_doc_delimiter) }}) + + // get filtered text + let exclude = '{{ copybutton_exclude }}'; + + let text = filterText(target, exclude); + return formatCopyText(text, {{ "{!r}".format(copybutton_prompt_text) }}, {{ copybutton_prompt_is_regexp | lower }}, {{ copybutton_only_copy_prompt_lines | lower }}, {{ copybutton_remove_prompts | lower }}, {{ copybutton_copy_empty_lines | lower }}, {{ "{!r}".format(copybutton_line_continuation_character) }}, {{ "{!r}".format(copybutton_here_doc_delimiter) }}) } // Initialize with a callback so we can modify the text before copy diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/sphinx-copybutton-0.5.0/sphinx_copybutton/_static/copybutton_funcs.js new/sphinx-copybutton-0.5.1/sphinx_copybutton/_static/copybutton_funcs.js --- old/sphinx-copybutton-0.5.0/sphinx_copybutton/_static/copybutton_funcs.js 2022-02-06 04:06:23.000000000 +0100 +++ new/sphinx-copybutton-0.5.1/sphinx_copybutton/_static/copybutton_funcs.js 2022-11-15 11:16:59.000000000 +0100 @@ -2,10 +2,25 @@ return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string } +/** + * Removes excluded text from a Node. + * + * @param {Node} target Node to filter. + * @param {string} exclude CSS selector of nodes to exclude. + * @returns {DOMString} Text from `target` with text removed. + */ +export function filterText(target, exclude) { + const clone = target.cloneNode(true); // clone as to not modify the live DOM + if (exclude) { + // remove excluded nodes + clone.querySelectorAll(exclude).forEach(node => node.remove()); + } + return clone.innerText; +} + // Callback when a copy button is clicked. Will be passed the node that was clicked // should then grab the text and replace pieces of text that shouldn't be used in output export function formatCopyText(textContent, copybuttonPromptText, isRegexp = false, onlyCopyPromptLines = true, removePrompts = true, copyEmptyLines = true, lineContinuationChar = "", hereDocDelim = "") { - var regexp; var match; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/sphinx-copybutton-0.5.0/sphinx_copybutton.egg-info/PKG-INFO new/sphinx-copybutton-0.5.1/sphinx_copybutton.egg-info/PKG-INFO --- old/sphinx-copybutton-0.5.0/sphinx_copybutton.egg-info/PKG-INFO 2022-02-06 04:06:32.000000000 +0100 +++ new/sphinx-copybutton-0.5.1/sphinx_copybutton.egg-info/PKG-INFO 2022-11-15 11:17:10.000000000 +0100 @@ -1,19 +1,18 @@ Metadata-Version: 2.1 Name: sphinx-copybutton -Version: 0.5.0 +Version: 0.5.1 Summary: Add a copy button to each of your code cells. Home-page: https://github.com/executablebooks/sphinx-copybutton Author: Executable Book Project License: MIT License -Platform: UNKNOWN Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 +Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3 :: Only -Requires-Python: >=3.6 +Requires-Python: >=3.7 Description-Content-Type: text/markdown Provides-Extra: code_style Provides-Extra: rtd @@ -75,5 +74,3 @@ ## Acknowledgements Many thanks to the excellent [clipboard.js library](https://clipboardjs.com/) for the lightweight javascript code that powers the copy button! - - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/sphinx-copybutton-0.5.0/sphinx_copybutton.egg-info/requires.txt new/sphinx-copybutton-0.5.1/sphinx_copybutton.egg-info/requires.txt --- old/sphinx-copybutton-0.5.0/sphinx_copybutton.egg-info/requires.txt 2022-02-06 04:06:32.000000000 +0100 +++ new/sphinx-copybutton-0.5.1/sphinx_copybutton.egg-info/requires.txt 2022-11-15 11:17:10.000000000 +0100 @@ -8,3 +8,4 @@ ipython myst-nb sphinx-book-theme +sphinx-examples