Git Product home page Git Product logo

sphinx-copybutton's Introduction

sphinx-copybutton

PyPI | Conda Version | Documentation

A small sphinx extension to add a "copy" button to code blocks.

See the sphinx-copybutton documentation for more details!

Copy Button Demo

Installation

You can install sphinx-copybutton with pip:

pip install sphinx-copybutton

Or with conda via conda-forge:

conda install -c conda-forge sphinx-copybutton

Usage

In your conf.py configuration file, add sphinx_copybutton to your extensions list. E.g.:

extensions = [
    ...
    'sphinx_copybutton'
    ...
]

When you build your site, your code blocks should now have little copy buttons to their right. Clicking the button will copy the code inside!

Customization

If you'd like to customize the look of the copy buttons, you can over-write any of the CSS rules specified in the Sphinx-CopyButton CSS file (link)

Development

Development should principally adhere to the EBP Developer Conventions

Sphinx-Copybutton is hosted on the pypi repository. After a release - following the EBP release instructions - confirm that the new version of Sphinx-Copybutton is posted to pypi.

Acknowledgements

Many thanks to the excellent clipboard.js library for the lightweight javascript code that powers the copy button!

sphinx-copybutton's People

Contributors

amotl avatar bcbnz avatar choldgraf avatar chrisjsewell avatar danielballan avatar dbitouze avatar dependabot[bot] avatar edmcdonagh avatar flywire avatar hugovk avatar ijaureguialzo avatar iwanb avatar jdillard avatar jeanas avatar mgeier avatar nikulinnn avatar nishikeshkardak avatar pablogsal avatar pradyunsg avatar pre-commit-ci[bot] avatar rkdarst avatar s-weigand avatar sappelhoff avatar seisman avatar stefanodavid avatar timhoffm avatar tzach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sphinx-copybutton's Issues

Warning: Extension does not declare if it is safe for parallel reading

Hi
We use this extension in scikit-image and i have the following warning:

WARNING: the sphinx_copybutton extension does not declare if it is safe for parallel reading, assuming it isn't - please ask the extension author to check and make it explicit
WARNING: doing serial read

[TOOL] Use bump2version for release management

While derping around in the source code I saw that you manually parse the version number in your setup.py:

# Parse version
init = Path(__file__).parent.joinpath("sphinx_copybutton", "__init__.py")
for line in init.read_text().split("\n"):
if line.startswith("__version__ ="):
break
version = line.split(" = ")[-1].strip('"')

So I wanted to recommend bump2version to you.
For me this simplified the workflow of releasing a new version quite a lot.
You can customice quite a lot, i.e. the commit message

message = ๐Ÿš€ RELEASE: Version {new_version}

So my workflow to release a new version is simply:

  • Update changelog + commit
$ bump2version major|minor|patch
$ git push --follow-tags

And let the CD handle the rest.

P.S.:
I also saw the note about using python>=3.4:

You can install ``sphinx-copybutton`` with ``pip``:
.. code-block:: bash

This could be made obsolete by setting the python_requires kwarg in the setup function to '>=3.4' or '>=3.5' (since py34 is dead).

Copy blanklines on matches(?)

Following #83 blanklines are not captured, e.g.

In [1]: import something
   ...:
   ...: print(something.__version__)

If the regex is set, will copy:

import something
print(something.__version__)

Release

Delayed "Copy" tooltip?

I like the appearance of the copy button, but I find it too noisy that the "Copy" tooltip appears whenever I move my mouse pointer over the button.

I think the tooltip does have its use, but what about delaying it a little bit (probably about a second, or even less?) to reduce the visual noise?

This would avoid the unwanted popping up when inadvertently moving over the button, but it would still provide feedback when hovering over it a little moment.

Sphinx-copybutton takes too much time to load

It took too much time to load these resources.

fa_url = 'https://use.fontawesome.com/releases/v5.2.0/css/all.css'
boot_css_url = "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
boot_js_url = "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"
pop_js_url = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"
clipboard_js_url = "https://cdn.jsdelivr.net/npm/clipboard@1/dist/clipboard.min.js"

Can you put these resources in a static directory?

(Edge browser) Using sphinx-copybutton introduces windowing of code

Hello! I have been planning to use your extension when building Python Like You Mean It, however I found that, in the Microsoft Edge browser, it collapses the code blocks into scrollable windows.

For example:

image

whereas on Chrome everything appears as I would expect:

image

This is especially disruptive for single-line code snippets as the code becomes obscured by the scroll bar.

I am using sphinx 3.0.1 and nbsphinx 0.6. Let me know if there is any other useful information that I can provide.

I am eager to start using your extension ๐Ÿ˜„

PyPI tarball contains a top-level directory `sphinx-copybutton-0.2.5/`

Hello,
i'm working to package sphinx-copybutton for debian, and noticed how the tarball in PyPI contains a top-level directory named sphinx-copybutton-0.2.5/ . this is could create troubles down the line when a new release is published, as now the 2 versions will be entirely different.

what's customary to do (and i believe the default behaviour of python3 setup.py sdist) is to publish the project files (as-in the files as shown in the GH page) at the top-level.

thanks for considering!

feature request: configurability of copyability

from scikit-hep/pyhf#721

a simple way is to add a configuration to allow for the last line to be copied or skipped. This should handle both cases. Additionally, could add a configuration indicating if the project wants to use >>> and ... so then you can just not copy lines that don't start with that.

In order to be a bit more flexible about how code snippets can be copied, it is true that there is no enforced consistency so that as of right now, the entire code-block is copied. This issue requests two separate things:

  1. The ability to toggle on/off whether the last line in a code-block should be copied (this doesn't necessarily assume a language)
  2. The ability to toggle on/off whether lines without >>> or ... should be copied (note: this one assumes python)
  3. Perhaps in the future, similar to above, the ability to toggle whether lines without > or $ should be copied

Things to fix for next release

error with pip-installing

pip install sphinx-copybutton
causes
ImportError: No module named pathlib

when I install
pip install pathlib and pip install sphinx-copybutton this causes
AttributeError: 'PosixPath' object has no attribute 'read_text'

my version: python -V -> Python 2.7.17

only working on python3/pip3? If yes pls update documentation for prerequisities.
I'll try to upgrade my python.

Prompt Regex Escaping Confusion

First of all thanks for the new Prompt RegEx feature โค๏ธ
I did just try it out and after some fiddeling around with the escaping, it works like a charm.

Expected behaviour

First of all I think in some edge cases it might make a difference to mention that the RegEx you type in your config.py is a JS RegEx and not a python one.
So that said IMHO it should work similar to this:

copybutton_prompt_text = r"<valid_js_reg_ex> "
copybutton_prompt_is_regexp = True

๐ŸŒˆ ๐Ÿฆ„

What I did

In my case the prompt I wanted to get rid of was of the form

r"In \[\d*\]: |\.\.\.: "

which is the jupyter console style and pretty much the same as the iPython style from the docs

"\\[\\d*\\]: |\\.\\.\\.: "

So it should be straight forward

"In \\[\\d*\\]: |\\.\\.\\.: "

as in the docs and I would be done?

But it didn't work, so I did some digging and ended up with:

"In \\[\\d*\\]: |\\.\\.\\.: |\\$ "

What internally happens

In my config.py, I set copybutton_prompt_text

copybutton_prompt_text = r"In \[\d*\]: |\.\.\.: "

which is the same as:

copybutton_prompt_text = "In \\[\\d*\\]: |\\.\\.\\.: "
>>> r"\\" == "\\\\"
True

Sphinx now replaces the context variable copybutton_prompt_text in copybutton.js_t and generates copybutton.js.
But when we look at that string which should have just been passed as is, it is missing backslashes.

'In \[\d*\]: |\.\.\.: |\$ '

Well this looks like a totaly valid JS RegEx, so this is fine?
And it would be if written like this (JS just wants keep people on their toes, so why not a different character for RegEx strings?):

/In \[\d*\]: |\.\.\.: |\$ /

Now the string gets passed to the RegExp constuctor, which expects strings to be escaped like python, if you don't use raw strings.
But it doesn't match.

> "In [1]: bar".match(new RegExp('^(In \[\d*\]: |\.\.\.: )(.*)'))
null

Why is this going wrong and why didn't the tests catch this?

TLDR

IMHO this all comes down ro JS RegExp 'helping' you in some cases when it can interprete what you might have ment, which gives you false security (false positiv match in the tests).

Details

Disclaimer I'm in no way a JS expert with insight into the internals, I just found this due to WTF moments + trail and error.

> let proper_regex = new RegExp('^(>>> |\\$ |In \\[\\d*\\]: |\\[\\d*\\]: |\\.\\.\\.: )(.*)')
undefined
> let false_positive_regex = new RegExp('^(>>> |\\$ |In \[\d*\]: |\[\d*\]: |\.\.\.: )(.*)')
undefined
>"$ bar".match(proper_regex)
(3)ย ["$ bar", "$ ", "bar", index: 0, input: "$ bar", groups: undefined]
> "[1]: bar".match(proper_regex)
(3)ย ["[1]: bar", "[1]: ", "bar", index: 0, input: "[1]: bar", groups: undefined]
> "[1]: bar".match(false_positive_regex)
(3)ย ["[1]: bar", "[1]: ", "bar", index: 0, input: "[1]: bar", groups: undefined]
> "...: bar".match(proper_regex)
(3)ย ["...: bar", "...: ", "bar", index: 0, input: "...: bar", groups: undefined]
> "...: bar".match(false_positive_regex)
(3)ย ["...: bar", "...: ", "bar", index: 0, input: "...: bar", groups: undefined]

So far so good, all testcases work fine, as we would expect since they pass.

> "In [1]: bar".match(proper_regex)
(3)ย ["In [1]: bar", "In [1]: ", "bar", index: 0, input: "In [1]: bar", groups: undefined]
> "In [1]: bar".match(false_positive_regex)
null

The only explaination I got for this behaviour, is that JS wants to "help" the user by guessing it's intention, like the famous adding thingy:

> "5" + 1
"51"

but at some points it is like "I don't get it", and the pattern that worked before fails.

Possible fix

Use repr in add_to_context

If this line was changed to:

      {"copybutton_prompt_text": r"{}".format(repr(config.copybutton_prompt_text))[1: -1]}

I know it looks ugly, but would add extra backslashes for escaping (maybe someone else has a more elegant solution).
I'm not sure how much escapeRegExp would need to be adjusted to those changes.

I didn't have luck with backslash replacing in JS:

> 'In \[\d*\]: |\.\.\.: '.replace(/\\/, '\\\\');
"In [d*]: |...: "
> 'In \[\d*\]: |\.\.\.: '
"In [d*]: |...: "

So in conclusion:
Python โค๏ธ
JS ๐Ÿ˜ 

P.S.: Wish we had the sphinx-copybutton on github, for the JS blobs I posted ๐Ÿ˜ข

Add copy button error:

Stacktrace:

Running Sphinx v1.6.7
...

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/webase-doc-cattwo/envs/latest/lib/python3.7/site-packages/sphinx/cmdline.py", line 305, in main
    opts.warningiserror, opts.tags, opts.verbosity, opts.jobs)
  File "/home/docs/checkouts/readthedocs.org/user_builds/webase-doc-cattwo/envs/latest/lib/python3.7/site-packages/sphinx/application.py", line 196, in __init__
    self.setup_extension(extension)
  File "/home/docs/checkouts/readthedocs.org/user_builds/webase-doc-cattwo/envs/latest/lib/python3.7/site-packages/sphinx/application.py", line 456, in setup_extension
    self.registry.load_extension(self, extname)
  File "/home/docs/checkouts/readthedocs.org/user_builds/webase-doc-cattwo/envs/latest/lib/python3.7/site-packages/sphinx/registry.py", line 207, in load_extension
    metadata = mod.setup(app)
  File "/home/docs/checkouts/readthedocs.org/user_builds/webase-doc-cattwo/envs/latest/lib/python3.7/site-packages/sphinx_copybutton/__init__.py", line 25, in setup
    app.add_js_file('clipboard.min.js')
AttributeError: 'Sphinx' object has no attribute 'add_js_file'

Exception occurred:
  File "/home/docs/checkouts/readthedocs.org/user_builds/webase-doc-cattwo/envs/latest/lib/python3.7/site-packages/sphinx_copybutton/__init__.py", line 25, in setup
    app.add_js_file('clipboard.min.js')
AttributeError: 'Sphinx' object has no attribute 'add_js_file'

My doc project is WeBASE-Doc

Add a PyPI badge to your repo homepage

Add this to your README.md file. So people know what is the latest version of your project.
Because I have to refresh your PyPI page to see if you released a new update. And allow people quickly jump to PyPI page.

[![PyPI](https://img.shields.io/pypi/v/sphinx-copybutton.svg)](https://pypi.org/project/sphinx_copybutton/)

This is how it looks like:

PyPI

Is sphinx_copybutton safe for parallel reading?

Building docs in parallel (O=-j4 option to sphinx-build) that include sphinx_copybutton emits the following warning:

WARNING: the sphinx_copybutton extension does not declare if it is safe for parallel reading, assuming it isn't - please ask the extension author to check and make it explicit
WARNING: doing serial read

Would it be possible to declare whether sphinx_copybutton is safe for parallel reading to get rid of this warning?

Remove outputs and prompts

Currently this will copy everything inside the code block. I was trying to add your sphinx-copybutton at scikit-learn. I think there are a lot of examples with outputs and prompts. For example,

>>> from sklearn import linear_model
>>> X = [[0., 0.], [1., 1.], [2., 2.], [3., 3.]]
>>> Y = [0., 1., 2., 3.]
>>> reg = linear_model.BayesianRidge()
>>> reg.fit(X, Y)
BayesianRidge(alpha_1=1e-06, alpha_2=1e-06, compute_score=False, copy_X=True,
       fit_intercept=True, lambda_1=1e-06, lambda_2=1e-06, n_iter=300,
       normalize=False, tol=0.001, verbose=False)

They are all tagged with class named gt,go,gp. I am not sure it is a standard name for sphinx-copybutton. So I modify your copybutton.js so that it filters out when I copy to clipboard. So this is the desired outcome:

from sklearn import linear_model
X = [[0., 0.], [1., 1.], [2., 2.], [3., 3.]]
Y = [0., 1., 2., 3.]
reg = linear_model.BayesianRidge()
reg.fit(X, Y)

If these class names gt,go,gp are common for sphinx-copybutton, I want to submit a PR.
Btw, the pop up in the Readme git is at the bottom and the actual pop up is on the left. Anyway, thanks for the extension.

The "copybutton_skip_text" feature is incomplete

I'm not planning to ever use this feature, but I still feel this should be mentioned:

The option copybutton_skip_text seems to expect a single line of text (by default '>>> '). However the Python prompt can also have another form, namely '... '.

For example, https://github.com/sbrunner/sphinx-prompt (example: http://sbrunner.github.io/sphinx-prompt/) seems to allow multiple prompts.

Also, if the prompt is ignored, shouldn't the outputs be ignored as well?

As another example, the Python docs have their own copy button (see for example here: https://docs.python.org/3/tutorial/controlflow.html), which does hide both types of prompts as well as the outputs.
Here's the code for that: https://github.com/python/python-docs-theme/blob/master/python_docs_theme/static/copybutton.js

As it is implemented currently, this feature could also backfire, for example if the code contains an e-mail conversation:

>>> BTW, my favorite ... is ...
>>> and I don't like ...
>>
>> What? I totally disagree!
>
> Anyway ...

I'm not sure how realistic such a case is, but I think I would be more at ease if such a case could be avoided.
The Python thing mentioned above seems to use Pygments annotations, which should also avoid such mistakes (I think).

Adding fade effect to icon

Maybe you'd like to consider adding a fade effect to the copy icon so that it only appears when hovering on the code block.
This should do it:

.highlight .copybtn {
	opacity: 0;
	transition: opacity 0.5s;
}
.highlight:hover .copybtn {
	opacity: 1;
}

New release

Using with read_the_docs template

Hello, I'm trying to use it with this template and get a green square (not gray) and a tiny icon.

How can I properly customize it? I've looked into the css file and there's no green background anywhere. Tried in Safari and Chrome, same results.

This is what I get:

grabacion de pantalla 2018-10-31 a las 12 19 36

[Improvement suggestion] Use Class Tag to enable any element copy to clipboard

I checked your code, looks like it assign a unique copy to each code block, and use that ID to copy code block to clipboard.

I am wondering, is it possible to just assign a special class to any html element, then your library automatically assign an ID to it, and do the same trick?

If you can implement that, you can define a custom rst:

.. role::
    :class: scb

Then you can use this to allow copy anything to clipboard:

Copy :scb:`This` to clipboard.

How's that sounds?

SVG image

Thanks for this great extension. If I want to use a different image instead of sphinx_copybutton/_static/copy-button.svg, can I overwrite it in css file some way???

Read config from conf.py

readthedocs/sphinx_rtd_theme#429 mentioned a need to read configuration from conf.py.

You can define configuration values in your setup() function by calling app.add_config_value()
You can get the value somwehere else using app.config (if app is available, like from an event callback) or from self.state.document.settings.env.config from your extensions run() function.
More direct access may be possible, but this works for me.

pypi package name

I was having trouble finding this on pypi because it is sphinx_copybutton and not sphinx-copybutton.

I would suggest changing either the docs or the package name.

Configure copybutton_prompt_text to support multiple prompt types

Is there any way to configure copybutton_prompt_text to support multiple prompt types?

For example, a simple python interpreter example with multi-line input:

>>> for i in range(3):
...     for j in range(3):
...         print(i * j)
0
0
0
0
1
2
0
2
4

Or an ipython test:

In [1]: a = 'foobar'
   ...: a
Out [1]:'foo'

How can I get this extension to remove the "In", "Out", ">>>", and ellipsis style prompts?

Copybuttons appear on a new line at the bottom of a cell instead of the top right corner

Describe the bug

Copybuttons appear on a new line at the bottom of a cell instead of the top right corner:
Screenshot at 2020-11-06 15-51-05
I don't know if it is related to the sphinx_rtd_theme.

Also, when I followed the docs to find some info on how to customize the CSS, in this section the following link lead nowhere:
https://github.com/ExecutableBookProject/sphinx-copybutton/blob/master/_static/copybutton.css

Environment

  • Python 3.7.6
  • notebook: 6.0.3
  • sphinx_rtd_theme: 0.5.0
  • Operating System: Ubuntu 20.04

Is this library compatible with Windows 10?

Hi,

I have tried installing on Windows 10 and I get errors. First I did this:

python -m pip install sphinx-copybutton
Collecting sphinx-copybutton
  Downloading https://files.pythonhosted.org/packages/23/28/5b32ff11b8dda007cafe6fff399758b222c757bcf3e7bd4b92c771e4b772/sphinx-copybutton-0.2.11.tar.gz (110kB)
    100% |################################| 112kB 2.0MB/s
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "c:\users\ross\appdata\local\temp\pip-install-ehoyds\sphinx-copybutton\setup.py", line 2, in <module>
        from pathlib import Path
    ImportError: No module named pathlib

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in c:\users\ross\appdata\local\temp\pip-install-ehoyds\sphinx-copybutton\

So then I did this:

python -m pip install sphinx-copybutton
Collecting sphinx-copybutton
  Downloading https://files.pythonhosted.org/packages/23/28/5b32ff11b8dda007cafe6fff399758b222c757bcf3e7bd4b92c771e4b772/sphinx-copybutton-0.2.11.tar.gz (110kB)
    100% |################################| 112kB 2.0MB/s
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "c:\users\ross\appdata\local\temp\pip-install-ehoyds\sphinx-copybutton\setup.py", line 2, in <module>
        from pathlib import Path
    ImportError: No module named pathlib

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in c:\users\ross\appdata\local\temp\pip-install-ehoyds\sphinx-copybutton\

and then this:

python -m pip install sphinx-copybutton
Collecting sphinx-copybutton
  Using cached https://files.pythonhosted.org/packages/23/28/5b32ff11b8dda007cafe6fff399758b222c757bcf3e7bd4b92c771e4b772/sphinx-copybutton-0.2.11.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "c:\users\ross\appdata\local\temp\pip-install-uurvx2\sphinx-copybutton\setup.py", line 23, in <module>
        for line in init.read_text().split("\n"):
    AttributeError: 'WindowsPath' object has no attribute 'read_text'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in c:\users\ross\appdata\local\temp\pip-install-uurvx2\sphinx-copybutton\

and now I'm a little bit stuck.

For information, this is the Python version I am using:

> python
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

Thanks in advance for any help you can offer.

Copy multi-line Python code

Situation

I would like to add a copy button to Python code of the following form

Code example
============

.. code-block:: python
        
    >>> import pandas as pd
    >>> data = dict(
    ... movie = ['Rambo', 'Commando', 'Mad Max'],
    ... actor = ['Sylvester Stallone', 'Arnold Schwarzenegger', 'Mel Gibson'],
    ... year = [1982, 1985, 1980]
    ... )
    >>> df = pd.DataFrame(data=data)
    >>> print(df)
          movie                  actor  year
    0     Rambo     Sylvester Stallone  1982
    1  Commando  Arnold Schwarzenegger  1985
    2   Mad Max             Mel Gibson  1980

I added the following to my conf.py

extensions = [
     'sphinx_copybutton',
]

copybutton_prompt_text = ">>> "
copybutton_only_copy_prompt_lines = True

I get the following output, when clicking the copy button in the generated HTML

import pandas as pd
data = dict(
... movie = ['Rambo', 'Commando', 'Mad Max'],
... actor = ['Sylvester Stallone', 'Arnold Schwarzenegger', 'Mel Gibson'],
... year = [1982, 1985, 1980]
... )
df = pd.DataFrame(data=data)
print(df)
      movie                  actor  year
0     Rambo     Sylvester Stallone  1982
1  Commando  Arnold Schwarzenegger  1985
2   Mad Max             Mel Gibson  1980

Problem

As expected the lines starting with >>> are copied and the prompt is removed. But

  • Lines starting with ... are kept as they are. I'm surprised that they aren't removed by the copybutton_only_copy_prompt_lines option. In any case: What I actually want is to treat ... also as prompt, i.e. keep the lines but remove the ... . This might be related to #52

  • The output table at the end, is also copied. Again this should not happen with the copybutton_only_copy_prompt_lines option present.

Suggestions

Im not very good at Js but if you guys acknowledge the issue I can make a PR. But if its easy for you, go ahead :)

Related

Thoughts on dropping the dependency on clipboard.js?

Is your feature request related to a problem? Please describe.

https://www.npmjs.com/package/clipboard-js -- clipboard.js is a deprecated package, and all the relevant APIs are available as vanilla JS in modern browsers.

Describe the solution you'd like

See https://tomspencer.dev/blog/2018/09/14/adding-click-to-copy-buttons-to-a-hugo-powered-blog/#final-code, which describes the entirety of what JS is needed to cleanly implement the same functionality on modern browsers.

Describe alternatives you've considered

Status quo? IDK any good alternatives to be honest.

Additional context

Nothing. I just realized that all Sphinx extensions that I generally recommend, are all now projects under the executablebooks umbrella. :)

Using sphinx-copybutton breaks custom layout

First off - very cool package. Thanks for putting it together.

I tried adding sphinx-copybutton to our docs and got some unexpected results. It seems that something in the plugin is messing with the css for our custom bootstrap theme/css.

image
Left: expected layout without sphinx-copybutton, Right: layout with sphinx-copybutton.

Do you have thoughts on what might be causing this or how to fix it?

Extension does not work with Sphinx 2.4.4

I try to move from Sphinx 1.8.x to Sphinx 2.4.4, and in the process sphinx-copybutton stopped working.
I see the following JS error in Chrome console:

copybutton.js:69 Uncaught ReferenceError: copybuttonSkipText is not defined
    at copybutton.js:69
    at Array.forEach (<anonymous>)
    at o.copyTargetText [as text] (copybutton.js:68)
    at o.value (clipboard.min.js:7)
    at HTMLBodyElement.<anonymous> (clipboard.min.js:7)

License field in setup.py

The LICENSE file contains the MIT license. The 'classifiers' field in setup.py mentions the MIT license. But the license field on line 16 of setup.py claims the license is BSD. I think that line should not be there at all, as the 'classifiers' field already supplies the license information.

Pressing copy button twice does not reset to correct text

When clicking the copy button twice, it reverts to "Copied!".

This is due to using the last data-tooltip in oldText rather than the localized string.

const temporarilyChangeTooltip = (el, newText) => {
const oldText = el.getAttribute('data-tooltip')
el.setAttribute('data-tooltip', newText)
setTimeout(() => el.setAttribute('data-tooltip', oldText), 2000)
}

Example:

  • First time, just click once
  • Second time, click twice within 2seconds-- any time after that the hover is "Copied!"

Can't make regexp work

When I try to use regular expressions in the copybutton_prompt_text field (with copybutton_remove_prompts and copybutton_prompt_is_regex set to True), sphinx-copybutton does not remove prompts.

To reproduce the behavior:

  1. Set conf.py as follows:
copybutton_prompt_text = r"\$\  |\#\ "
copybutton_prompt_is_regexp = True
copybutton_remove_prompts = True

  1. Run sphinx-build

Expectations

I expect sphinx-copybutton to detect and omit from copying the user "$ " OR root "# " prompts (i.e., exclude both prompt strings from copying) .

Environment

A virtual environment (Dockerized) running:

  • Python version 2.7 or 3.7
  • Sphinx version 1.8.3 or 3.1.2
  • Operating System: OS X 10.15.5

Additional context

I am embarrassed to open this as a bug report, as my assumption is that this is either my ineptitude with regexp (though I have tried every permutation that I can imagine) or a weird setup issue. Is there a canonical environment in which regexps are functional?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.