-
Notifications
You must be signed in to change notification settings - Fork 55
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
[ENH] add sphinx-copybutton extension #615
Conversation
(Image: CC-BY license, The Turing Way Community, & Scriberia. Zenodo. http://doi.org/10.5281/zenodo.3332808) Wohoo! 🎉 Thanks for opening your first pull request to the DataLad Handbook! 😎 We really appreciate your time and effort to contribute to the project - you're amazing! 👏 |
For example, copying this cell (screenshot of this): gives me: cd ../../
cat << EOT >> notes.txt
datalad save -m "Add note on datalad clone" ... all lines prefixed with But copying this cell (screenshot of that): gives me the whole cell, because no # enter your home directory using the ~ shortcut
% cd ~
% git config --global --add user.name "Bob McBobFace"
% git config --global --add user.email bob@example.com we could also use a regex to configure more than one prefix we want to "detect". I think this works very nicely :-) WDYT? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, nice! Thanks for the addition, @sappelhoff. I tried it out locally, and it works very well for single lines of code with a $
prefix.
I've toyed around with the regex for a bit locally, trying to make here docs or multi-line commands work, but so far I've failed with one edge-case-problem after the other ;-) I'm happy to at least make the single line case work much easier with this addition.
Could you please make a small note mentioning the copy-button in docs/intro/narrative.rst about copy-pasting code?
And also please feel free to add yourself to the zenodo.json file :)
hey @all-contributors please add @sappelhoff for infra, tool |
I've put up a pull request to add @sappelhoff! 🎉 |
👍 I tried to use the ⎘ icon in the intro as an approximation of the "copybutton" ... it'd be best perhaps to use the actual copybutton icon, but it may also be overkill. Do you have a link to the examples that currently don't work? |
Anything that is a multi-line command, split with
in the end of the second section, or any of the
FTR: I've opened a feature request to copy-button: executablebooks/sphinx-copybutton#105. |
I see, I didn't know what a "here document" was until now :-) thanks for opening the feature request! |
Its ancient, but super convenient to write formatted text into a file from the terminal :-) I'd say we wait for a response on the feature request until proceeding. I'll cherry-pick 6d8cabc into master, later, though, just to have you in zenodo.json when we make the next release. |
agreed, it'd be great to support these two types of code snippets as well. Thanks for the cherry-picking. Good thing I made a separate commit for that ;-) |
Unfortunately we didn't get much input so far, but I took some time and prepared a PR that may suffice for our needs: executablebooks/sphinx-copybutton#126 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @adswa I added the requirement to sphinx-copybutton and my PR just got merged. I now updated this PR, and I think the line-continuation and here-document cells now work like we want them to work.
I'd appreciate a review! Below two links to test the copybutton in the RTD build artifact:
-
example for line continuation from this page: https://datalad-handbook--615.org.readthedocs.build/en/615/basics/101-102-populate.html
-
example for here-document from this page: https://datalad-handbook--615.org.readthedocs.build/en/615/basics/101-103-modify.html
This is fantastic @sappelhoff , thank you so much for your efforts! I apologize in advance for a delay, a number of deadlines loom over me. It looks good on first sight, an I hope I can get to try it out and comment more within this week :) |
This is so cool! ❤️ Apologies for getting to this with such a delay :( Again one of these things that would have been done in 5 minutes had I just not pushed it at the end of my todo-list ... 🤦 @mih, @yarikoptic check this out! It works flawlessly! |
No worries, thanks for maintaining this book! I am happy to see this in :-) |
closes #75
based on #75 (comment), this PR (through the build artifacts) will allow us to practically inspect how using "sphinx-copybutton" may work.