In many cases, OneNote will remove text format when you copied and pasted text , including: text color, background color, some space are removed.
And these text formats are not in HTML format, they may be rich text format.
Lead to the original formatted text, beyond recognition.
Here's an example with the PowerShell ISE that comes with Windows.
We copy the code in the PowerShell ISE that comes with Windows.
These codes appear to be colored. It is easy to distinguish between variable names and strings.
In OneNote for Windows 10, press Ctrl + V to paste the PowerShell code and you'll find that all the colors in the code are gone.
To keep the color of your code, you can use the Paste Rich text feature of the Gem Menu.
Click Gem Menu for OneNote UWP -> “Edit” menu -> “Paste Rich Text” menu item.
The background color will even be preserved.