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

Proposal to add copy button to code examples [copy of gh-107024] #154

Open
churnikov opened this issue Aug 30, 2023 · 4 comments
Open

Proposal to add copy button to code examples [copy of gh-107024] #154

churnikov opened this issue Aug 30, 2023 · 4 comments

Comments

@churnikov
Copy link

Hi!

I'm planning to move this work to this repo.

@AA-Turner Suggested to me in this PR python/cpython#107037 (comment) to do that. Please tell me, what do you think :)
Do you agree that that's a good idea?

If so, I guess I would need to rewrite this function, right?
https://github.com/python/python-docs-theme/blob/main/python_docs_theme/static/copybutton.js

@AA-Turner
Copy link
Member

We'd probably want to evaluate what exists in the literature thus far; it might be that the copybutton.js that I rewrote is redundant. It functions to hide certain Pygments classes denoting output from interactive console display blocks.

Should we decide to add a "click to copy" button, I think the functionality should be merged with the existing button.

A

@churnikov
Copy link
Author

May I ask you, what do you mean by "We'd probably want to evaluate what exists in the literature thus far;"? :)

@AA-Turner
Copy link
Member

E.g. https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard; https://clipboardjs.com/ -- there are many ways to and libraries for interacting with the clipboard -- ought we abandon our JavaScript, ought we adopt a pre-existing library, ought we use the browser APIs, etc.

A

@ferdnyc
Copy link

ferdnyc commented Jan 26, 2024

FYI, there's also a pre-made sphinx_copybutton extension available, that uses clipboard.js.

(Which, btw, can):

  1. Automatically remove prompts from the copied lines:

    copybutton_prompt_text = r">>> |\.\.\. "
    copybutton_prompt_is_regexp = True
    copybutton_remove_prompts = True  # (default)
  2. Copy only lines with prompts, when it finds prompts:

    copybutton_only_copy_prompt_lines = True  # (default)
  3. Copy multiple wrapped lines and re-assemble them, if the first one starts with a prompt:

    copybutton_line_continuation_character = "\\"

Full docs: https://sphinx-copybutton.readthedocs.io/

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

No branches or pull requests

3 participants