What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 131 Stack Exchange communities.

Possible Duplicates:
How to post code in SO
How do I format my code blocks?

when i post code here is ends up all mangled, how do i make it look pretty?

for example posting //#include (minus the //) ends up looking like this:

include

what am i doing wrong?

share|improve this question

migrated from stackoverflow.com May 25 '10 at 17:23

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

marked as duplicate by Andrew Grimm, Pops, Jon Seigel, waiwai933, ChrisF Mar 30 '11 at 8:52

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.

1  
Isn't there an explanation to the right of where you type the question? –  Earlz May 25 '10 at 18:46
    
Actually there doesn't seem to be a duplicate for this question, though an old one of mine is related meta.stackexchange.com/questions/34588/… Maybe this should be a FAQ? –  Earlz May 25 '10 at 18:47

6 Answers 6

If you post code or XML, highlight those lines in the text editor and click on the "code" button (101 010) on the editor toolbar to nicely format and syntax highlight it.

alt text

share|improve this answer
6  
@marc_s -- not a circle, not freehand, it is red and points in roughly the correct area; I give it a 5.5. –  tvanfosson May 25 '10 at 20:26
1  
@tvanfosson: out of 6? Not bad..... heck - I'm a dev, not a graphics artist! ;-) You don't want to see my complete UI's...... –  marc_s May 25 '10 at 20:29

If you want to do this manually, you add 4 spaces in front of every line of code.

With the editor, there is a code button (101010) you can press after highlighting the code.

share|improve this answer

You surround your code in backticks `` (like this)

Or for block code, you indent your code by four spaces:

function test()
{
    alert("it works!")
}

You can view the source for this post here.

share|improve this answer

You can also use keyboard shortcut: just highlight and hit ctrl-k

share|improve this answer

like this, highligh what you want then click the code button

#include
share|improve this answer

I think this is one of those things that should belong on meta.stackoverflow.com or some such, but... in the post box, if you click the orange question mark in the top-left of the box, it will take you to a page with Markdown help. Basically, you prefix each line with four spaces:

like this 

and you should see the text show up as 'code' in the preview area below the edit box.

share|improve this answer