Issue copy and pasting code/rich text


I’m using Scrivener to write some technical documentation and I’m including snippets of code. I generate these using the atom text editor ,so I can get lines numbers, as well as syntax highlighting for the code as appropriate. This mostly works as displayed below…


Sometimes this doesn’t work…


I cannot for the life of me figure out why this is a problem. I’ve tried copying from different apps and pasting the code into a new scrivener document. Some bits of code just don’t seem to cooperate. The formatting is sometimes lost when changing the style to “Code Block” other times this works fine. Any ideas as to what is going on here?



P.S Getting images displayed in the post is a bit tricky. Saving post as a draft also loses the attachments.

What’s wrong in the second image? Numbers start at the wrong point? Something else?

I think you’re pasting in some kind of “field code”, which is always iffy.

Can you pinpoint when something is going wrong—is it while copying or while pasting? When it is the former it is not a Scrivener issue but an Atom issue. Which I suspect because Atom is a cross-platform app that most certainly uses non-macOS native techniques.

Yeah, to expand on the last comment, I would double-check that Atom is actually copying formatted text when it doesn’t work in Scrivener. A simple way of doing that would be to open TextEdit and paste into that. If it comes out as plain-text there as well, then there is something wrong with Atom.

Another way to check is to use the Edit ▸ Show Clipboard command in Finder. If the pasteboard is plain-text, it will indicate it in the footer bar, and it should be obvious from the preview as well.

No code/syntax highlighting. Lines numbers are correct.

Mostly it works. Probably 8/10 times it’s fine but other bits of code simply refuse to cooperate. When it works the code pastes straight in as a code block. All formatting / colour is maintained (as in example 1).

When it doesn’t work the code block setting is ignored / reverted and it’s pasted in the default paragraph style. Syntax highlighting is maintained. If then one highlights the code and selects “code block” all the highlighting is removed (as in example 2).

In atom I used a “Copy as RTF” plugin. It works.