This is insanely cool! Just implemented it and works like a charm. Thanks.
Edit: I started to notice that this removes all formatting, including list items. I want to be able to easily identify my lists in both edit and preview, so I changed the first line in the above CSS to this:
div:not(.CodeMirror-activeline)>.CodeMirror-line span.cm-formatting-header,
div:not(.CodeMirror-activeline)>.CodeMirror-line span.cm-formatting-strong,
div:not(.CodeMirror-activeline)>.CodeMirror-line span.cm-formatting-em,
Happy to be told if there’s a better way to do this. But it just changes changes things from removing ALL formatting, to only removing formatting for headers, bold and italicised text.