-
Notifications
You must be signed in to change notification settings - Fork 82
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
docs: Add copy buttons to code snippets in docs with sphinx-copybutton #721
Conversation
does this also copy the output of the command? e.g. |
Current sphinx-copybutton just copies whatever is inside the code cell (minus stripping out some characters like prompts). If there's a way to know what part of the code cell should be skipped entirely (e.g. because it's an output), I'd be open to a PR in sphinx-copybutton that implements it! Here's the JS function that does the text copying: |
thanks @choldgraf! at least for python shouldn't it be safe to say everything that does not start with |
@lukasheinrich it would be if all projects used A lot of projects just dump raw code in there (so no prompts at all) |
9a3a13a
to
73b91f8
Compare
Codecov Report
@@ Coverage Diff @@
## master #721 +/- ##
=======================================
Coverage 95.89% 95.89%
=======================================
Files 54 54
Lines 2998 2998
Branches 424 424
=======================================
Hits 2875 2875
Misses 78 78
Partials 45 45
Continue to review full report at Codecov.
|
285225f
to
5c834aa
Compare
@choldgraf , a simple way is to add a configuration to allow for the last line to be copied or skipped. This should handle both cases. Additionally, could add a configuration indicating if the project wants to use |
Maybe we should make an issue over at |
I think I'd be +1 on that idea @kratsg - we'd need to think through the potential use-cases. We'd need to consider whether there is a case that someone wants to copy the stuff after prompts, and also the stuff that comes after that. +1 on opening an issue to discuss there |
5c834aa
to
46e2c9d
Compare
46e2c9d
to
2d4f29c
Compare
Requires sphinx-copybutton v0.2.8 or higher
2f1d060
to
12bfc67
Compare
Just checking up on this tonight, and as @choldgraf is 💯% awesome, he already did all this — thank you Chris! 🎉 As of so the example for now gives when pasted import pyhf
pyhf.set_backend("pytorch")
a = pyhf.tensorlib.astensor([-2, -1, 0, 1, 2])
pyhf.tensorlib.clip(a, -1, 1) @lukasheinrich @kratsg To see this in action, c.f. the Read the Docs build: https://pyhf.readthedocs.io/en/docs-use-sphinx-copybutton/index.html |
Description
Add
sphinx-copybutton
to thedocs
extra to add copy buttons to all code snippet blocks.Thanks for tweeting and for the great work, @choldgraf!
This makes all of our docstrings even nicer now as the copy button removes the Python REPL prompts:
so that when pasted you get
Checklist Before Requesting Reviewer
Before Merging
For the PR Assignees: