|
3 | 3 | This section describes major ways to use and control `sphinx-copybutton`'s behavior.
|
4 | 4 |
|
5 | 5 | (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 | + |
6 | 36 | ## Strip and configure input prompts for code cells
|
7 | 37 |
|
8 | 38 | By default, `sphinx-copybutton` will copy the entire contents of a code
|
@@ -366,22 +396,3 @@ button.copybtn {
|
366 | 396 | See the [Sphinx documentation on custom CSS for more information](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_static_path).
|
367 | 397 |
|
368 | 398 | [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