Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude unselectable text from being copied #138

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion docs/index.rst
Expand Up @@ -372,6 +372,17 @@ In this case, all elements that match ``your.selector`` will have a copy button
added to them.


Exclude text
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Exclude text
Exclude text from being copied

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You may exclude elements matching CSS selectors from being copied by specifying the `copybutton_exclude` option in ``conf.py``.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You may exclude elements matching CSS selectors from being copied by specifying the `copybutton_exclude` option in ``conf.py``.
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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about instead of hard-coding .linenos, we just set this value to be a list that defaults to ['.linenos']. Then if somebody wants to define their own exclusion list, they can provide it and include .linenos as well on their own. This seems a bit simpler


By default `.linenos` is excluded. If you specify the `copybutton_exclude` option it will replace the default.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
By default `.linenos` is excluded. If you specify the `copybutton_exclude` option it will replace the default.
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 highlighter of Sphinx) for "prompt", e.g. `$` in a shell-session.

I am unsure if we want .gp by default, but since sphinx_rtd_theme (and probably others should as well) makes it unselectable by default, it seems reasonable that we mirror that behavior.

But, if we add .gp by default, then themes which don't un-select .gp will confuse users. If we do add it, users in themes that understand pygments have to change things. Hm, seeming more like like interpreting the CSS has some sort of advantages but I'm not sure if it's worth the extra work yet...


Modify the copy button's CSS
============================

Expand Down Expand Up @@ -466,7 +477,7 @@ Then run the docs build:

.. code-block:: console

$ cd doc
$ cd docs
$ make html

.. toctree::
Expand Down