sphinx-copybutton icon indicating copy to clipboard operation
sphinx-copybutton copied to clipboard

Allow setting `copybutton_prompt_text` for specific codeblocks only

Open aantn opened this issue 3 years ago • 3 comments

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 avatar Jan 10 '22 12:01 aantn

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
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! :tada:

welcome[bot] avatar Jan 10 '22 12:01 welcome[bot]

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.

aantn avatar Jan 10 '22 13:01 aantn

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.

rkdarst avatar Jul 06 '23 13:07 rkdarst