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

While posting anything on SO, I never type <code> tags. However, when my post appears on the site, the code are properly formatted. I checked the source and found that the code part of the post is put within the <code> tag. This works even for a small code like rec(0).

I want to know what is the algorithm to identify that a particular text is code and not regular text.

share|improve this question

migrated from Jun 30 '10 at 8:51

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

No, it is not, you have to select and click on the 101 button, right? – vodkhang Jun 30 '10 at 6:57
I just noticed that if you manually added code tag in your post, it is formatted as code (with silver background). – devcoder Jun 30 '10 at 6:58
@vodkhang, I never done this but still code in my posts appear formatted. That is why the question came to my mind. – devcoder Jun 30 '10 at 7:00
@devcoder, Are you sure no one edited your posts, applying the correct formatting? =) – Tomas Lycken Jun 30 '10 at 7:01
@Tomas, Yes, I am sure. because after clicking on the submit, it appeared as formatted. I believe, no one can format it in such a little time span. – devcoder Jun 30 '10 at 7:04
@Tomas, as Kobi pointed out below, someone modified my post. I never knew it. +1 for this. Thanks. – devcoder Jun 30 '10 at 7:08
@devcoder: A short timespan is no guarantee - the SO community is fast as greased lightning ;) – Tomas Lycken Jun 30 '10 at 7:28
@Tomas, Yes. SO community is very fast. Today I practically experienced this. – devcoder Jun 30 '10 at 7:38

You have only one post with code that I could find: .
Look at the history - it was edited for you by another user:

So the answer is: by building a successful community :)

share|improve this answer
@Kobi, You are right. It was modified. Thanks. – devcoder Jun 30 '10 at 7:06
Kobi, I recalced your SO rep after migration as requested; 18,175 -> 18,027 – balpha Jun 30 '10 at 8:53
@balpha - Thanks. I see it lost the accepted answer, but it looks like a known bug:… . – Kobi Jun 30 '10 at 9:12

It just checks to see if the phrase is surrounded with tick characters, or the block is indented by four spaces.

i.e. It looks for formatting instructions, it doesn't actually detect code.

share|improve this answer
in one post, I wrote a line as below without any formatting or tick. string str = "abc"; and it appeared as code on the site. – devcoder Jun 30 '10 at 7:01

You must log in to answer this question.

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