Skip to content

Override clipboard text for code blocks #6086

@ti-mo

Description

@ti-mo

Context

No response

Description

Our documentation contains shell snippets including a command's expected output, like:

image

One of our users complained about the clipboard button grabbing everything in the block, which is indeed rather annoying for something like shell-session. Even though the code highlighter correctly recognizes the prompt and the output, that doesn't translate to the behaviour of the clipboard button.

Related links

I ended up here (facelessuser/pymdown-extensions#1802) in my search, but that only really affects text selection. It's still a nice UX improvement, though, and I'll follow the advice given there as well.

Use Cases

I started out trying to influence clipboard.js' behaviour by setting { .shell-session data-clipboard-target="foo !important" data-clipboard-text="go mod init ebpf-test && go mod tidy" } on the block (ending up on the div), but this only works when I remove the data-clipboard-target property from the button using my browser's devtools.

Since it can't easily be determined what the correct behaviour is in shell-session blocks containing multiple lines with commands, I figured it would be nice to be able to manually specify the snippet used by the clipboard button. XYProblem, but it looks like a relatively straightforward change from a distance.

It looks like setupClipboardJS() already takes data-clipboard-text into account, but data-clipboard-target seems to take precedence if both are specified on an element. Not sure why that's the case.

Visuals

No response

Before submitting

Metadata

Metadata

Assignees

No one assigned

    Labels

    change requestIssue requests a new feature or improvementresolvedIssue is resolved, yet unreleased if open

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions