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

Make it easy to copy-paste from Markdown code blocks #6209

Closed
MarcSkovMadsen opened this issue Jan 16, 2024 · 1 comment
Closed

Make it easy to copy-paste from Markdown code blocks #6209

MarcSkovMadsen opened this issue Jan 16, 2024 · 1 comment
Labels
type: feature A major new feature
Milestone

Comments

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Jan 16, 2024

It would really, really be valuable if Panel code markdown blocks supported copy-paste. All competing frameworks support this.

A small example.

import panel as pn

pn.extension()

pn.Column("""
An example

```python
import panel as pn

pn.extension()
```

```bash
https://panel.holoviz.org
```
""").servable()

image

I would like something similar to what Quarto provides (below). Its only shown when the upper, right corner is hovered upon.

image

We also have the copy-paste functionality in our docs. It could also be similar to that. I'm just not a fan of the green check mark that shows when the code has been copied as the green does not go well with the colors used in my (work) apps.

Workaround

Make a separate copy button. Its not as nice a UX though.

import panel as pn

DEFAULT_KWARGS = {
    "button_type": "default",
    "description": "Copy to the clipboard",
    "icon": "clipboard",
    "sizing_mode": "fixed",
    "width": 30,
    "margin": 0,
}


def create_copy_to_clipboard_button(text, **kwargs):
    for key, value in DEFAULT_KWARGS.items():
        if not key in kwargs:
            kwargs[key] = value

    button = pn.widgets.Button(**kwargs)

    copy_code = f"navigator.clipboard.writeText(`{text}`);"
    button.js_on_click(code=copy_code)

    return button

Additional Context

@MarcSkovMadsen
Copy link
Collaborator Author

Solved by #7451

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A major new feature
Projects
None yet
Development

No branches or pull requests

2 participants