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 noticed that if a code section that's clearly C#, contains some HTML or XML in a comment, it will be rendered as 100% HTML. Example answer here.

Example that would highlight wrongly on SO:

string s = "hello world";
var i = s.Length();  // comment with <html><img></html>

At SO it shows the part <html><img></html> with html-syntax highlighing both during editing and after commit. I noticed that on Meta, this snippet isn't highlighted at all. So, potentially this issue only occurs on SO.

Edit: Shadow Wizard edited the referred to question, so the original effect is not visible anymore.

share|improve this question
up vote 4 down vote accepted

When you post code written in language that does not appear as part of the question tags, you have to "manually" tell the code highlighter what is this language.

This is done by adding such line above the code, with one blank line below it:

<!-- language: lang-cs -->

This will tell the highlighter to treat it as C# code for example.

I have edited your answer as well. :)

For the record, the highlighter tried to parse the code as XML which appears as question tag.

share|improve this answer
Ah, thanks, looks much better now. I actually experimented with <!-- language: c# --> but apparently didn't get it right. So, it is true then, SO no longer looks at the code snippet and guesses, but now looks at the question tags only. – Abel Nov 15 '11 at 11:59
@Abel It never looked at the code snippet. Until tags were considered for the hoghlighting, we just used prettify's default "kinda works with any code" highlighter. – balpha Nov 15 '11 at 12:20

You must log in to answer this question.

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