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

Allow setting copybutton_prompt_text for specific codeblocks only #149

Open
aantn opened this issue Jan 10, 2022 · 3 comments
Open

Allow setting copybutton_prompt_text for specific codeblocks only #149

aantn opened this issue Jan 10, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@aantn
Copy link

aantn commented Jan 10, 2022

Description / Summary

We're using sphinx-copybutton for our documentation and love it. Thank you very much.

We'd like to allow stripping the prompt text for specific blocks of code but not all of them.

You can see an example here:

https://docs.robusta.dev/master/getting-started/installation.html

I'd like to strip $ from one code block on that page (and only copy the line with $). The other code blocks don't contain $ so I'd like to avoid doing any tricks there.

Value / benefit

It would make the copybutton_prompt_text feature usable for us.

Implementation details

No response

Tasks to complete

No response

@aantn aantn added the enhancement New feature or request label Jan 10, 2022
@welcome
Copy link

welcome bot commented Jan 10, 2022

Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.

If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).

Welcome to the EBP community! 🎉

@aantn
Copy link
Author

aantn commented Jan 10, 2022

To clarify, the stripping isn't the main issue. The main issue is determining which lines to copy and that should sometimes only be lines with $ and sometimes all lines.

@rkdarst
Copy link
Collaborator

rkdarst commented Jul 6, 2023

Now that a new version is released, I would say: don't use copybutton_prompt_text, use copybutton_exclude. copybutton_prompt_text hard codes patterns to exclude . copybutton_exclude excludes text by CSS classes... and pygments (the highlighter) can magically label the text for you!

copybutton_exclude = '.linenos, .gp'

For example, console session, it excludes the $ sign:

$ echo hi
hi

If it semantically isn't a console session where prompts are not something to copy but some complete text to be copied:

$ echo hi
hi

This doesn't just work for console but any pygments language that tags prompts as .gp.

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

No branches or pull requests

2 participants