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

I saw a question on Stack Overflow tagged : 'Could not autowire field' exception in Spring

The post contains both XML- and Java code. To my surprise, this question correctly prettified. Both XML and Java code are formatted correctly. This surprised me, because similar posts on also contain XML- and C# code, but are not correctly formatted (for example, this question). Why is this?

I know how highlighting hints work; that isn't the issue.

I've done quite a number of edits on questions and answers tagged to format the code. Are those edits necessary?


Kiamlaluno's answer is providing a possible explanation. Can someone with sufficient privileges on Stack Overflow confirm that:

  • To be confirmed: this Spring.NET question has tags with conflicting syntax highlighting settings. It would be strange for general tags like exception|logging|aop||aspects.

  • Confirmed by balpha (see comments): the does not have a code-highlighting language set.

Edit 2

Kiamlaluno summarizes nicely how the system is supposed to work, but this can only be confirmed by someone with sufficient privileges on Stack Overflow (10k+, I suppose). If someone can confirm Kiamlaluno's "hypothesis", I'll be happy to accept his answer.

Edit 3

I'll keep a short list of posts with unexpected formatting:

share|improve this question
2 does indeed not have a code-highlighting language set. And it shouldn't, since it's not constrained to a specific language. – balpha Dec 4 '11 at 16:57

Which syntax highlighting is used is influenced from three factors:

  • the global option, that on Stack Overflow is set to "auto detect"
  • the option for specific tags, which can be set by moderators for each tag
  • a comment placed before the code, which overwrites the other settings

In a comment for his answer, Shog9 said:

Autodetect actually works reasonably well for most C-like languages, XML, HTML, etc... Well enough that if you expect languages to be mixed you'll want the associated tags to all be set to autodetect. That's probably less important here than it is on, say, SO, but probably still worth doing for some of the more tangential tags (ajax would be a good candidate I suspect).

The default for the tags is to use the global option, but it can be set to "none" or a value that is specific for a programming language (e.g. "lang-c++"). If the question is using two tags for which the syntax highlighting option conflict with each other, then the code will not be highlighted.

Shog9 reported the following, in another answer:

When two different language tags occur on a question, the syntax highlighter switches back to auto-detecting the language. So you should only have trouble when the language actually being used can't be auto-detected (for instance: VB).

share|improve this answer
So you're saying that spring domain-driven-design don't conflict, but exception logging aop aspects do? – Arjan Dec 2 '11 at 13:05
That's clear, so I should I conclude that the question has conflicting tags? which would that be then - it's got all kinds of "general tags"? And the spring question not? I think that the settings for spring and tags should be the same, only difference being java vs c#. – Marijn Dec 2 '11 at 13:07
Considering that the global setting is set to "auto detect" on Stack Overflow, there must be a conflict between the settings for the tags used by the question. – kiamlaluno Dec 2 '11 at 13:08
I wonder what happens to the question if its answer would not explicitly specify a language... – Arjan Dec 2 '11 at 13:09
@Arjan The syntax highlighting used is defined from the question, and its tags, not from the answers. If I answer a question for which a tag sets the syntax highlighting to C++ (and not "auto detect"), then also the code in my answer will be highlighted as if it were C++ code. I can force a syntax highlighting in my answer (using HTML comments), but what I set for my answer doesn't influence the question. – kiamlaluno Dec 2 '11 at 13:19
@Arjan To notice that the answer for the question tagged forced the syntax highlighting using "<!-- language: lang-xml —>." If you take off that comment from the answer, and save it, you will notice that the code is not highlighted. I tried it right now, and then re-added that comment. This means that what set in the answer doesn't influence the question. – kiamlaluno Dec 2 '11 at 13:26
For now, I'll only upvote for the consise summary. If someone can confirm the conflicting tags and the tag language config, I'll be happy to accept this as the answer. – Marijn Dec 4 '11 at 13:22

You must log in to answer this question.

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