|
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, 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 | + |
6 | 33 | ## Strip and configure input prompts for code cells
|
7 | 34 |
|
8 | 35 | By default, `sphinx-copybutton` will copy the entire contents of a code
|
@@ -35,6 +62,13 @@ use the following configuration:
|
35 | 62 | copybutton_prompt_text = ">>> "
|
36 | 63 | ```
|
37 | 64 |
|
| 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 | + |
38 | 72 | ### Using regexp prompt identifiers
|
39 | 73 |
|
40 | 74 | 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 {
|
366 | 400 | 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 | 401 |
|
368 | 402 | [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