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

Possible Duplicate:
Which tools and technologies build the Stack Exchange Network?
What syntax highlighting library is used on Stack Overflow?

How does Stack Overflow handle its syntax highlighting? Example:

String[] files = Directory.GetFiles();
int count = files.Length;

Syntax highlighting is nice. But I don't see any formatting mumbo jumbo in the page source. Only <pre> and <code> tags. How is it done?

share|improve this question

migrated from Jan 21 '13 at 21:20

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Martijn Pieters, Arjan, Adam Lear Jan 21 '13 at 22:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

...and is there any way to tell it about the language when it's wrong? – Anton Kovalenko Jan 21 '13 at 21:07
It's probably a library, so I think you'd better look at the linked script (or the resources tab in the inspector). There are plenty of libraries handling syntax highlighting, so why would you reinvent the wheel? – 11684 Jan 21 '13 at 21:08
@AntonKovalenko there is! Just add <!-- language: [desired langiage] --> above your code, as stated in the formatting help. – 11684 Jan 21 '13 at 21:10
The code is highlighted using Javascript. That's why it looks all clean when you look at the source, but in fact, it's just about to be transformed into a "mess" of <span>s. – zneak Jan 21 '13 at 21:11
Well, now this is interesting. I get the mess of spans when I Inspect Element in Chrome. If I view source, I get clean output with only pre and code. – Gigi Jan 21 '13 at 21:16
@Gigi that is because the 'source' is the response from the server, the inspect element reflects the actual state of the elements, after it has been processed by JS etc. – 11684 Jan 21 '13 at 21:17
Thanks for clarifying. I'm not very familiar with JavaScript. What kind of code would you need to do something of the sort, transforming one kind of content to another? Any function calls in particular? – Gigi Jan 21 '13 at 21:19
And you could study how the Prettify project works from the source code. – Martijn Pieters Jan 21 '13 at 21:29

This is answered here - see the section of the answer labelled "Syntax Highlighting", it even includes a link ;)

share|improve this answer
+1, although you might add in your answer it is done with Prettify, because at first sight it might seem you misunderstood the question and are clarifying how you can tell Stackoverflow to highlight your syntax. (I think you should read more than 'first sight', but I just want to save you from unnecessary down votes.) – 11684 Jan 21 '13 at 21:13
@11684 agreed - that's what I thought at first. Maybe Kolink might want to add some more detail for the internet users out there who are curious and may thus easily satisfy their curiousity. – Gigi Jan 21 '13 at 21:15

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