This post is related to two older posts. One is an old feature request, Promote Stack Overflow HTML, JS, CSS Stack Snippets, which did not receive much attention but I think is good. The second is a nice post discussing bad snippet usage - Should it be more obvious that stack snippets are only meant for HTML/CSS/JS?.
According to the second post, there may be around 30% questions (only, no answers) using snippets with wrong tags (no CSS/HTML/JS). While this is bad usage, it is rather easy to fix on edit.
The other problem - H/J/C questions not using the snippet (specifically where the code is in the question, not a jsfiddle
link which is worse in my opinion) is more annoying. It seems like it happens often, with new users at least (Is there a percent somewhere we can see, like that second post? Might be useful to see if this is actually widespread). For me at least fixing these is a bit tedious.
So I was wondering, is there any way to mark some text, ctrl-something to get it surrounded with the appropriate snippet comment line, and similarly for H/J/C?
I would like to stress - I am not requesting any language detection here. It's up to an editor to mark the text they want to enclose in the tags. That means for usage of JS, HTML, and CSS, you would have to mark the text 4 times (once for each language, and one each to enclose everything in the snippet. Also, I'm just asking if there is some way to get this done currently; so it's not really a feature request.
Also, is it easy to detect a snippet in the question (answer)? If so, might be worth turning this into a feature request to address both of the above - on pressing "post", an appropriate warning such as
You have tagged
javascript
but you are not using the snippet tool
with an appropriate image, and vice-versa can pop up to enlighten the user. This is short enough and I'm guessing most new users just make an honest mistake/miss the snippet so it might actually help.
Discussion of the feature part of the question
@Oleg noted this warning could become annoying for one line code pieces and the such, and I agree. The only workaround I can think of is a rep barrier where no warnings show (a small one, ~10-20).
As @Boltclock stresses, this should be a mere soft improvement suggestion, not a warning, and have no repercussions. New users pasting code dumps should just be notified of this.
Feature basics (updating with discussion):
- No language detection should be implemented. This is a tag (and snippet) detection suggestion.
- Should have a very low rep barrier, just so new users get acquainted. After 10-20 rep, no warning should appear.
- Should pop up once per question as a suggestion only, perhaps with a link to snippet usage FAQ. This should not be a warning.
- This won't fix the question for the user, just point them in the right direction of what to do; since there is no code detection, it would be impossible.
<!-- begin snippet: js hide: false console: true babel: false --> <!-- end snippet -->