Copy with syntax highlight



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?



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


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.


Screenshot? :sparkles:


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


Thanks @braver and @leedohm :smile:



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.


Alas on Win10 at least copy-with-style is serious broken (doesn’t work):

and is has a few other issues:

but copy-as-rtf works:

and copy-highlighted:

though both don’t give me what I see in Atom, restyling the highlights in their own way in the resulting paste. Which I find odd.

Have to admit it would be nice to see a working package that reproduced the on-screen look of Atom in the pasted result.


Found this one too:

But it seems totally defunct, just puts what looks like RTF onto the clipboard which pastes as RTF code not respected (so imagine some format identifier missing from what’s put onto the clipboard)