Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 158 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

My answer here is on a question that is tagged . When I am editing the question I occasionally see syntax highlighting applied to the code block. However, when I view the question/answer on the site I don't. How do I get syntax highlighting applied?

share|improve this question
Related:… – BalusC Mar 30 '11 at 3:19
@Chi: That question is older than the one I linked to in my answer. – Jon Seigel Mar 30 '11 at 3:24
@Jon: and the cause of everything (yours is linked in there as well) – BalusC Mar 30 '11 at 3:25
up vote 3 down vote accepted

Heh... Turns out, someone set the default highlighting language for to lang-html. This was initially done for as well, but reverted when it turned out this broke all those questions involving both HTML and JavaScript blocks. The system even warns you about it now:

Setting a language to a value other than default should ONLY be done if the odds of a XML, Javascript, or HTML code block in the same post is very low,are you sure you wish to make this change?

...But apparently, was overlooked when this was fixed for . And so combining and would break syntax highlighting for the script, since as far as the system was concerned, 's lang-html was more important than 's default.

I've set the default language back to... default.

share|improve this answer
Excellent find, nice work. – Phrogz Apr 7 '11 at 1:59

The language key you need is lang-js. I've corrected your post. Note also, that it works by simply omitting the language specifier comment -- since is on the question, it defaults to that in this case.

For a full list of languages supported, see Jeff's answer here.

share|improve this answer
Well, that doesn't explain why the JS highlight wasn't applied, in spite of the presence of javascript tag. – BalusC Mar 30 '11 at 3:18
@Chi: Good point. Maybe it was just a glitch in the system. I edited one of my sandbox posts (10k only) using javascript as the language and it worked ok. – Jon Seigel Mar 30 '11 at 3:24
Glitch or not, the decision to disable the syntax highlighting altogether when there's no match on the tags was imo a poor decision. – BalusC Mar 30 '11 at 3:28
Thanks for the answer and the edit on the question. Hopefully automatic language detection will work better in the future, but for now that "hidden" list of languages supported and the magic comment needed to tag them is quite helpful. – Phrogz Mar 30 '11 at 4:25
@Phrogz: You're welcome. It's still a bit unclear why the highlighting didn't work in the first place, but at least we were able to fix it. – Jon Seigel Mar 30 '11 at 17:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .