Copy/Paste/Copy/Paste to terminal without formatting - eviltoast

This is killing me.

We have a snippet of code on a web page. Users copy the code to a text editor, make a small change, then copy the modified version and paste it into a terminal window.

And it fails to run.

I’ve confirmed this happens with both Textedit and Notes, and also that copying from the web page and pasting directly into a terminal works fine (although without the necessary code changes).

It’s something in the text editor copy; and there’s no way to either “copy as plaintext” or “paste without formatting” into a terminal.

Does anyone know how I can work around this?

EDIT Apparently some (but not all) spaces (octal 040) are being converted to octal “302 240”. I can’t figure out how to stop it!