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

Merged
merged 1 commit into from
Nov 20, 2024

Conversation

stevepiercy
Copy link
Contributor

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
Contributor 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.

@trallard
Copy link
Collaborator

Since this has been approved for a while I will go ahead and merge and if needed we can iterate on this.

Thanks for your contribution @stevepiercy ✨🙏🏽

@trallard trallard merged commit 30cdb3f into pydata:main Nov 20, 2024
25 checks passed
agoose77 pushed a commit to executablebooks/sphinx-book-theme that referenced this pull request Nov 25, 2024
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.

3 participants