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

When using the copybutton in code blocks, exclude copying the prompt #2036

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stevepiercy
Copy link

When I use the copybutton in code blocks, I expect to be able to paste the code into my terminal without having to delete the prompt that gets copied. This PR fixes that issue by excluding CSS classes that Pygments generates in code blocks.

See https://sphinx-copybutton.readthedocs.io/en/latest/use.html#automatic-exclusion-of-prompts-from-the-copies

@@ -113,6 +113,7 @@
# Exclude copy button from appearing over notebook cell numbers by using :not()
# The default copybutton selector is `div.highlight pre`
# https://github.com/executablebooks/sphinx-copybutton/blob/master/sphinx_copybutton/__init__.py#L82
copybutton_exclude = ".linenos, .gp"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I also noticed on that page:

To skip all console outputs, add .go to the string above.

@stevepiercy did you intentionally not include that? Seems also useful (prompt outputs are usually not runnable code and would interfere with copy-paste-run)

Copy link
Author

Choose a reason for hiding this comment

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

@drammock I didn't include it because console output is not something that I would copy and paste into a terminal session. For example, in MyST source:

```console
A
billion
lines
of

...

stacktrace
```

However it might be useful in some other context of which I am not aware. Perhaps notebooks or some other utility? I selected only the options with which I am familiar. I can ammend my PR to what you think is best.

Copy link

Coverage report

This PR does not seem to contain any modification to coverable code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants