While editing 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?

3 Answers 3


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

  • Hmm, might I have been remembering the preview or old behavior?
    – Gnome
    Mar 21, 2010 at 5:40
  • @Jeff: how many spaces? 8? It would be better to adjust the posted text to not have the tabs, then. Mar 21, 2010 at 5:46
  • @John, late reply: Markdown assumes a tab width of 4.
    – Arjan
    Apr 15, 2011 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:

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

  • 1
    My concern is that the tabs persist in the text. They are still there when I edit. Apr 15, 2011 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, 2011 at 17:42
  • (In other words: there are spaces, no tabs, in the rendered result.)
    – Arjan
    Apr 15, 2011 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. Apr 15, 2011 at 18:45
  • 1
    Something must have changed. The example I linked to in the question no longer contains tab characters. Apr 15, 2011 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, 2011 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, 2011 at 19:17
  • (@John, things slightly changed this week; see updated answer.)
    – Arjan
    May 12, 2011 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.

You must log in to answer this question.

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