Copy with syntax highlight


#1

Hi.

I very frequently print or copy sections of my codes. However, I want these sections to be copied/printed with their syntax highlighted.
Notepad++ has a feature called “copy text with syntax highlighting”. Is there any similar feature in Atom? If not, is there a workaround to do that?

Thanks


#2

I haven’t seen that feature no. I assume it could be built into a package though.


#3

The clipboard API allows arbitrary metadata to be included in a copy but It would be hard to make all places that you can paste understand your metadata. If you want to paste outside of atom you’d have to use the OS api. That can be done but it isn’t trivial.


#4

Screenshot? :sparkles:


#5

So in a few words, there isn’t any easy way to do that in Atom like in Notepad++. Thanks Mark for answering me.


#7

Thanks @braver and @leedohm :smile:


#8

#9

I created copy-with-style for this purpose. It supports several presets, if you copy to more than one destination that has different requirements, and can copy as both HTML and RTF. It reads the internal Atom DOM to get the colors, so what you copy will actually match what you see in the editor, and it has support for piping the result to an external script or tool instead of directly to the clipboard.

That last point is needed when copying to, for example, Google docs on OS X. Google docs support copy and paste of HTML markup with preserved formatting, but it requires the clip in the clipboard to be tagged as HTML, which it isn’t by default. I shared the one liner ruby script I used to achieve this on OS X in the package’s wiki on Github and encourage you to do the same if you write, or put together, a script or workflow for pasting with format into some other program on some other platform.