executablebooks / sphinx-copybutton

Add a "copy" button to code blocks in Sphinx
https://sphinx-copybutton.readthedocs.io/en/latest/
MIT License
250 stars 49 forks source link

Adding (necessary) lines to what is copied #112

Open dbitouze opened 3 years ago

dbitouze commented 3 years ago

Is your feature request related to a problem? Please describe. No

Describe the solution you'd like Adding (necessary) lines to what is copied.

More precisely, I'd like to use sphinx-copybutton for a LaTeX FAQ. It is common for such a FAQ:

For instance, instead of:

\documentclass{article}
\usepackage{xcolor}
\begin{document}
This a \textcolor{red}{text in red}.
\end{document}

only:

This a \textcolor{red}{text in red}.

is given (with a mention to the necessary xcolor package).

But if the user just copy and paste the latter and compile it, he will go into troubles. On the other hand, giving the whole code for each example would be tedious to read.

So what could be nice is to display only:

This a \textcolor{red}{text in red}.

and the actual copied text would be:

\documentclass{article}
\usepackage{xcolor}
\begin{document}
This a \textcolor{red}{text in red}.
\end{document}

Additional context

I'm aware this could be considered as unsafe but maybe a pop up could warn the user the actual content of what has been copied.

welcome[bot] commented 3 years ago

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: