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} Code generator doesn't keep it's formatting when pasting into word #1492

Open
danbuntu opened this issue Jan 31, 2024 · 7 comments

Comments

@danbuntu
Copy link

When you generate code by right clicking and selecting 'generate code' it'#s all lovely and formatted with nice colouring to herlp distinguish the parts.

If you click the copy button and then paste into msword the layout formatting is kept but the colouring is removed.

It would be great if the colours were kept.

@sanjai0py
Copy link
Member

sanjai0py commented Jan 31, 2024

hey @danbuntu. would you mind sharing more details about the issue you're facing? It would be great if you could attach any relevant information that could help better understand the problem. Thanks!

@danbuntu
Copy link
Author

Hi @sanjai0py
No problem

This image shows the generate code box with a curl request in it. Headers, data, key etc are all different colours

image

This image shows what happens when this is pasted into word - the layout formatting is kept but the colours are removed. As such it's harder to read.

image

@sanjai0py
Copy link
Member

Thanks for the update. It looks like the issue might be coming from MS Word, as the formatting is not being preserved when pasted. Have you tried Google Docs instead?

Here are some helpful links: https://answers.microsoft.com/en-us/msoffice/forum/all/when-pasting-text-from-web-into-ms-word-it-will/3844d928-58d1-43c6-89f9-cd147288ab75 https://www.quora.com/Why-does-the-font-look-different-when-pasted-into-Microsoft-Word-from-the-clipboard-compared-with-copy-pasting-directly-from-the-original-source-a-web-page.

Let me know if you need anything else!

@danbuntu
Copy link
Author

It's the same problem in Google docs

@danbuntu
Copy link
Author

danbuntu commented Feb 2, 2024

For anyone else have the same problem I can recomend this plugin for word:

https://appsource.microsoft.com/en-us/product/office/WA104382008

It does a good job of formatting the code

@sanjai0py
Copy link
Member

hey, thanks for the update @danbuntu! this walkaround might help people. but i did some research and found out something interesting. turns out that the contents can be copied as rich text, but it's not as easy as it sounds. i tried tweaking the settings of react-copy-to-clipboard package, which is used for copying the editor values when copy to clipboard is pressed, but it only copies the text as plain text by default. i also tried passing an options parameter into it like {format:"text/html"} [1], but it didn't work. i even tried using electron's inbuilt way to copy text to clipboard [2], but that didn't work either. the last and final way is to try using codemirror's features [3], which are unfortunately quite hard to implement, and the code examples/discussions are from a decade ago. so, i think the only hope to make this feature work is when this #1450 for adding monaco gets merged. i think this feature will be implemented out of the box then.

[1] copy-to-clipboard - npm (npmjs.com)
[2] clipboard - Electron (electronjs.org)
[3] rich text copy - CodeMirror

@danbuntu
Copy link
Author

danbuntu commented Feb 2, 2024

Ok thats sounds like a possible postive solution then at some point.
Thank you for looking into this.

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

No branches or pull requests

3 participants