This is related to this feature request around "training videos" but is more specific.
It seems to me that it wouldn't be too hard to make a pretty good guess about when a question contains code that isn't formatted. Some heuristics would be biased towards particular languages, but even so, I think the team could make some good guesses. Heuristics might include:
- Consecutive lines which contain amounts of whitespace differing by 4 spaces in several places
- Common programming language keywords
- Lots of symbols compared with normal text
- Potentially language-specific detection: semi-colons at the end of lines, braces on lines on their own or at the end of lines
- Single-letter words other than "a" and "I"
- Long words with underscores or capitalsWithinTheWord
In an ideal world, it would be great to guess at the precise chunk of text which contained the code, and present the user with a choice:
It looks like you were trying to post code, but didn't know about the formatting. Did you mean it to look like this (original) or this (formatted)?
User then chooses the appropriate option, and is shown what they should have done in the input box as well.
<pre>
rather than{}
because the highlighter messes it up.