sphinx-copybutton icon indicating copy to clipboard operation
sphinx-copybutton copied to clipboard

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

Open MacHu-GWU opened this issue 7 years ago • 2 comments

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?

MacHu-GWU avatar Oct 18 '18 23:10 MacHu-GWU

Hmmm - yep that does seem like it should be possible. Currently it just looks for div.highlight pre sections, but if there were a "special" class that sphinx-copybutton knew to look for, you could make these contents copyable. The CSS might not look as seamless in this case though :-/

choldgraf avatar Oct 19 '18 01:10 choldgraf

I believe the code in Pull Request 138 could be easily adapted to add this functionality.

bicarlsen avatar Sep 21 '21 06:09 bicarlsen