Possible Duplicate:
How do I format my code blocks?

When adding a code block of several lines, must I indent EACH LINE of the code block by 4 spaces, or just the first line? In the following block, each line of the code is indented 4 lines.

echo "each line is here indented four spaces" ;
setCookie(\'testtest\', '.$book['code'].', time()+ 172800);
<script type="text/javascript">alert("does this work");</script>

In my earlier posts, I was using the "code sample" {} button on the toolbar above this text entry box. That didn't work well at all... So here comes the 2nd code block, same code but only the first line of the code block indented the four space. Just seeing if the format is different.


echo "each line is here indented four spaces" ; setCookie(\'testtest\', '.$book['code'].', time()+ 172800);

alert("does this work");

And this is the end of this post.

marked as duplicate by Jon Seigel, random Mar 28 '11 at 3:30

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.

migrated from stackoverflow.com Mar 27 '11 at 18:17

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

  • 3
    Select the code and press ctrl+K – Erik Mar 27 '11 at 18:04
  • You didn't have to post this question, you could see the preview at the bottom as you typed it. – Ilya Kogan Mar 27 '11 at 18:05
  • You may be right... I am new to StackOverflow (fewer than 10 posts) and have been figuring it out. The {} toolbar button's tooltip "code sample" was slightly misleading (not all code samples, just a partial snippet) and I wanted to be sure that it would be the same. I'm not yet a pro coder myself, so I'm never sure how things are working "under the hood." – user159392 Mar 27 '11 at 22:24
  • Highlight the text that you want as code. Click the code button {} or press control K, this button will toggle your highlighted text between code or non code - no need to indent. – DermFrench Feb 1 '13 at 17:46

You must indent each line; see http://daringfireball.net/projects/markdown/syntax (which is linked at the bottom of the StackOverflow markdown help for details. I put together a tiny Mac OS X service to do this for me using Automator (it just runs sed).


There's the answer...

The code sample button {} on the toolbar is for a single line of inline code.

To paste a block of code, each line of the code block must be indented four spaces.

  • +1 for answering your own question :) – faif Mar 27 '11 at 18:05
  • 7
    but you can select a whole block of code and click the code sample button {} on the toolbar, it will indent that whole code block 4 spaces. – gideon Mar 28 '11 at 3:32
  • THANK YOU -- That's a great tip! – user159392 Mar 29 '11 at 14:48
  • 1
    @user Np. Also the keyboard shortcut is Ctrl + K – gideon Mar 29 '11 at 15:04

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