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

DESKTOP: Adding copy to clipboard button for code block #3024

Closed
wants to merge 3 commits into from
Closed

DESKTOP: Adding copy to clipboard button for code block #3024

wants to merge 3 commits into from

Conversation

Rishabh-malhotraa
Copy link
Contributor

@Rishabh-malhotraa Rishabh-malhotraa commented Apr 11, 2020

fixes: #2383

Changes

copy-to-clipboard

Added copy to clipboard functionality for fences-code block

Note: I only tested this on the desktop app I did not test to for mobile.

TODOS:

  • correcting the unit test case
  • improving the regex used to replace the pre tag (it is not accurate for cases having multiple lines right now )
  • 🐞 : the button moves to the left when there is an option to scroll horizontally

I will make the changes and update this as soon as possible

@Rishabh-malhotraa
Copy link
Contributor Author

@PackElend can you please label me, thank you!

@laurent22
Copy link
Owner

Hmm, when you think about it the "copy to clipboard" button is unrelated to Markdown rendering. It's more a property of the UI, like the context menu for example. So it feels like all this shouldn't be in MdToHtml but elsewhere, maybe in the viewer component.

@Rishabh-malhotraa
Copy link
Contributor Author

So it feels like all this shouldn't be in MdToHtml but elsewhere, maybe in the viewer component.

I did so based on the conversation in this PR, the reasoning of doing it in MdToHTML is that we only want this button to show when the fence block is rendered, which could be easily achieved by hooking additional rules to the fence token generated by markdown-it plugin, but I see your point too and I'll look into what changes can be made

@Rishabh-malhotraa
Copy link
Contributor Author

Rishabh-malhotraa commented Apr 14, 2020

Hmm, when you think about it the "copy to clipboard" button is unrelated to Markdown rendering. It's more a property of the UI, like the context menu for example. So it feels like all this shouldn't be in MdToHtml but elsewhere, maybe in the viewer component.

@laurent22 , Sir can you be a bit more specific about exactly what kind of change is required,
there are two ways that I can think of, that will get us the desired result

  • Hook additional rule to the fence token while rendering markdown (current behaviour)
  • search the dom for the pre tag and add additional HTML content(button) to it
    I believe the latter is what you were referencing to in your comment, can you please specify exactly what is required so I can go an updating this PR. thank you!

@tessus tessus added the desktop All desktop platforms label Apr 19, 2020
@laurent22 laurent22 closed this May 14, 2020
Repository owner locked as resolved and limited conversation to collaborators May 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
desktop All desktop platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a "Copy code" button on code blocks
4 participants