There is a tool available for formatting the code snippet in OneNote — Note Highlight project — https://github.com/elvirbrk/NoteHighlight2016
Well and good; with some added complexity of installing the plugin and so on…
Is there any alternative?
Well, not the code syntax formatting the way the plugin does but a properly indented code with a decent readability — see if that suffices for you.
Step 1
Paste the code into a beautify engine such as, https://beautifier.io/
Beautify the code on the site. Copy this code.
Step 2
Paste the code with Keep Source formatting option: