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

[Feature] Copy to clipboard functionality for Code Block component #1500

Open
2 tasks done
Jettonn opened this issue Sep 5, 2024 · 1 comment
Open
2 tasks done

[Feature] Copy to clipboard functionality for Code Block component #1500

Jettonn opened this issue Sep 5, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@Jettonn
Copy link

Jettonn commented Sep 5, 2024

Initial checklist

  • I agree to follow the code of conduct
  • I searched issues and discussions and couldn’t find anything (or linked relevant results below)

Problem

Code Block component is really useful, but since it's created not to be extended by the user it's hard to add a copy-to-clipboard functionality to the component (although you can change the icons, buttons, etc for language selector).

Solution

It would be handy to be able to add functionalities yourself (extend the components) or just support copy to the clipboard button.

Alternatives

Let users extend milkdown components and plugins

@Jettonn Jettonn added the enhancement New feature or request label Sep 5, 2024
@sensiblearts
Copy link

I'm trying to copy the current selection as markdown.

     theEditor.editor.action((ctx: Ctx) => {
            const editorView = ctx.get(editorViewCtx);
            let selection = editorView.state.tr.selection;
            // now what...?
            // I searched through `selection`'s fields, recursively,
            // but could not find a method to get the markdown.      
    });

Perhaps, something like selection.getMarkdown() would solve mine and would subsume your code block copy?

Then it's just a matter of navigator.clipboard.write(), isn't it?

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

No branches or pull requests

3 participants