Earlier today I wanted to copy and paste code that I had written into a OneNote notebook. However, when I pasted it, it lost all formatting!
Luckily I was able to find a workaround (credit where credit is due) where if you paste your code into Microsoft Word, and then copy/paste from Word to OneNote, it will pick up the correct highlighting, etc.
When you paste into OneNote, be sure to use "source formatting" if you don't want the font to be the OneNote default.
Also, since it's an Office product, if you don't want the red squiggly lines under each "misspelled" word, you'll need to check the spelling and ignore all. It's easiest to do if you click on the Review tab and select Spelling. Then keep clicking on the Ignore button until you're done.
Hope this helps!