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

While editing http://stackoverflow.com/questions/2354800/winforms-control-begininvoke-asynchronous-callback, I found that it actually contains tab characters (despite the fact that they cannot be entered into the editor via keyboard). That seems to screw up the formatting.

Can someone explain how the editor and display code handle spaces and tabs in code blocks?

share|improve this question

3 Answers 3

MarkdownSharp will convert any tabs it finds to spaces. At least, once the post hits the server, that is what happens.

share|improve this answer
    
Hmm, might I have been remembering the preview or old behavior? –  Gnome Mar 21 '10 at 5:40
    
@Jeff: how many spaces? 8? It would be better to adjust the posted text to not have the tabs, then. –  John Saunders Mar 21 '10 at 5:46
    
@John, late reply: Markdown assumes a tab width of 4. –  Arjan Apr 15 '11 at 16:47

When using tabs in your code: while typing then most browsers will show tabs based on a width of 8. But while displaying the Markdown renderer will convert those into spaces based on a tab width of 4.

For example, what while editing might look like:

In editor, mixed tabs and spaces align

...will, since May 2011, nicely use all spaces in the preview:

Preview, just like the final rendering

...which perfectly matches how only spaces are used in the cooked HTML after saving:

|1234567890123456789012345678901234567890123|
|   x   x   x   x   x   | (using tabs in the "code")
|   x       x       x       x       x       | (using spaces)

The Markdown source (with the tabs) itself is kept as a revision, for a next edit.

share|improve this answer
1  
My concern is that the tabs persist in the text. They are still there when I edit. –  John Saunders Apr 15 '11 at 17:21
    
The Markdown is HTML-ified upon save, @John. This "cooked HTML" also includes the (then current) title of raw trilogy internal links and has tags converted into the mouse-hover-thingies. The Markdown itself is kept as a revision, for a next edit. –  Arjan Apr 15 '11 at 17:42
    
(In other words: there are spaces, no tabs, in the rendered result.) –  Arjan Apr 15 '11 at 18:14
    
this is muddied a bit by the way you are mixing spaces and tabs in the above sample, also the leading characters. Try a "pure" example using just spaces or just tabs in the left margin. –  Jeff Atwood Apr 15 '11 at 18:45
1  
Something must have changed. The example I linked to in the question no longer contains tab characters. –  John Saunders Apr 15 '11 at 18:57
1  
@John, I'm sure Roger manually replaced them with spaces; he even refers to this very question in the revision comment. Your last version still had tabs and spaces mixed in, for example, private void RefreshComplete(). –  Arjan Apr 15 '11 at 19:15
1  
(@Jeff, true, but I thought mixing tabs and spaces was the point of the question? Anyway: no worries!) –  Arjan Apr 15 '11 at 19:17
    
(@John, things slightly changed this week; see updated answer.) –  Arjan May 12 '11 at 6:21

I just added an answer to the Formatting Sandbox with a little demo. View the source on it for a comparison.

Either 1 tab or 4 spaces is required. Almost all the time when I copy code, it's indented at least 1 level (usually a namespace), so for most cases, tabs should work fine to get the formatter to detect that a code sample is being posted.

share|improve this answer

You must log in to answer this question.

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