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.

migrated from stackoverflow.com Jun 30 '10 at 8:51

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

  • 1
    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
  • 2
    @devcoder, Are you sure no one edited your posts, applying the correct formatting? =) – Tomas Aschan 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 Aschan 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: What is the difference in string.Equals("string") and "String".Equals(string)? .
Look at the history - it was edited for you by another user: https://stackoverflow.com/posts/3142766/revisions

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

  • @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: meta.stackexchange.com/questions/15275/… . – 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.

  • 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 .