Skip to content

Commit ab414ca

Browse files
rkdarstcholdgraf
andauthored
DOCS: Improve docs related to text exclusion (#187)
* docs/use: Improve docs about copybutton_exclude - As in #185, document the current sate of copybutton_exclude and saw how to turn it on (since the default just got turned off for backwards compat). - Review: worth a read to make sure it isn't too confusing. * Update docs/use.md --------- Co-authored-by: Chris Holdgraf <[email protected]>
1 parent fae1f06 commit ab414ca

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

docs/use.md

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,36 @@
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.
11+
Sphinx by default excludes prompts from being selectable.
12+
However, by default `sphinx-copybutton` will copy these prompts (for backwards compatibility with the other "manually-selectable exclude" options).
13+
14+
To make `sphinx-copybutton` skip all prompt characters generated by pygments, use the following setting:
15+
16+
```{code-block} python
17+
copybutton_exclude = '.linenos, .gp'
18+
```
19+
20+
To **skip all console outputs**, add `.go` to the string above.
21+
22+
For automatic exclusion, make sure to use the right highlight language.
23+
For example: `pythonconsole` instead of `python`, `console` instead of `bash`,
24+
`ipythonconsole` instead of `ipython`, etc.
25+
26+
This setting can also be used to exclude arbitrary css classes from
27+
being copied. By default `.linenos` are excluded. `.linenos` is the
28+
Sphinx default for line numbers, `.gp` is the Pygments class for the
29+
prompts, and `.go` is the class for console outputs.
30+
31+
This setting conflicts with most of pattern-based copy-selection
32+
settings below, so should not be used with them. This will hopefully
33+
be improved in the future.
34+
35+
636
## Strip and configure input prompts for code cells
737

838
By default, `sphinx-copybutton` will copy the entire contents of a code
@@ -366,22 +396,3 @@ button.copybtn {
366396
See the [Sphinx documentation on custom CSS for more information](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_static_path).
367397
368398
[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)