Skip to content

Commit 11527dc

Browse files
committed
docs/use: Improve docs
- Improves #185 by documenting things, but there are likely better fixes later. - Does not fix that issue, just makes it more clear in the short term. - Review: worth a read to make sure it isn't too confusing.
1 parent 4345c48 commit 11527dc

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

docs/use.md

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,33 @@
33
This section describes major ways to use and control `sphinx-copybutton`'s behavior.
44

55
(configure-copy-text)=
6+
7+
## Automatic exclusion of prompts from the copies
8+
9+
The Sphinx code highlighter, Pygments, tags the prompts (`>>>`, `...`,
10+
`In [1]:`, `$`) of console sessions, and sphinx by default excludes
11+
prompts from being selectable. Sphinx-copybutton follows this
12+
default. For automatic exclusion, use the right highlight language:
13+
`pythonconsole` instead of `python`, `console` instead of `bash`,
14+
`ipythonconsole` instead of `ipython`, etc.
15+
16+
This is controlled via the `copybutton_exclude` setting. If you want
17+
to also exclude the output from commands from being copied, you can set:
18+
19+
```{code-block} python
20+
copybutton_exclude = '.linenos, .gp, .go'
21+
```
22+
23+
This setting can also be used to exclude arbitrary css classes from
24+
being copied. By default `.linenos, .gp` are excluded. If you specify
25+
the `copybutton_exclude` option it will replace the default.
26+
`.linenos` is the Sphinx default for line numbers, and `.gp` is the
27+
Pygments class for the prompts. `.go` is the console outputs.
28+
29+
**This setting should be disabled (set to ``.linenos``) when using
30+
custom specifications as described below.**
31+
32+
633
## Strip and configure input prompts for code cells
734

835
By default, `sphinx-copybutton` will copy the entire contents of a code
@@ -35,6 +62,13 @@ use the following configuration:
3562
copybutton_prompt_text = ">>> "
3663
```
3764

65+
This does *not* play nicely with the automatic exclusion, so for this,
66+
and most of the other settings on this page, you should also set the
67+
following to disable language-based exclusion:
68+
```python
69+
copybutton_exclude = '.linenos'
70+
```
71+
3872
### Using regexp prompt identifiers
3973

4074
If your prompts are more complex than a single string, then you can use a regexp to match with.
@@ -366,22 +400,3 @@ button.copybtn {
366400
See the [Sphinx documentation on custom CSS for more information](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_static_path).
367401
368402
[regex101]: https://regex101.com
369-
370-
371-
## Exclude text from being copied
372-
373-
You may exclude elements matching CSS selectors from being copied by
374-
specifying the `copybutton_exclude` option in ``conf.py``. For
375-
example, a viewer usually doesn't want to copy the line numbers, and
376-
CSS provides a way to exclude this. This option implements that
377-
option for sphinx-copybutton as well.
378-
379-
380-
```{code-block} python
381-
copybutton_exclude = '.exclude_me'
382-
```
383-
By default `.linenos, .gp` are excluded. If you specify the
384-
`copybutton_exclude` option it will replace the default. `.linenos`
385-
is the Sphinx default for line numbers, and `.gp` is Pygments (the
386-
default highlighter of Sphinx) for "prompt", e.g. `$` in a
387-
shell-session. `.gp` is excluded in upstream Sphinx by default.

0 commit comments

Comments
 (0)