I answered my own question but cannot get the answer formatted correctly. There are two issues. For one, I wish to enter a script as part of my numbered list (directly under #6). However, I am unable to get it formatted as code, unless I enter the "period" on the line directly before the script starts. If you edit the answer, and remove the period, the script is no longer formatted as code, even though each line is preceded by 4 spaces.

Secondly, after the code, I wish to continue the numbered list (to #7). However if I edit the question and enter a "7." after the code block (and before "Save the script...") its automatically converted into a "1." as if I am starting a new list.

What am I doing wrong, and how can I avoid such formatting issues in the future?

  1. Code blocks in list items:

    • If you want to include a code block in a list item, you need to indent it with eight spaces as opposed to the usual four.

      An example:

      1. List item text.
              Example code block
         More list item text following example code block.
    • 1. ↵
              Example code block
         List item text following example code block.

      If you want to begin a list item with a code block, you need to add a single space after the period, add two line breaks (denoted above by ↵), then begin the code block (with eight spaces for indentation).

    Also see this other answer.

  2. It is not currently possible to start a list with an arbitrary number using Markdown. This is a known limitation with no known remedy.

| improve this answer | |
  • Speaking of normal lists: Actually you don't need 8 spaces. In your post, not even 1. Try editing and remove the spaces before the dot items... Nothing will change. If you want to indent something that has no item (i.e. a normal paragraph) between the 1 and 2, just leave a space before the numbers and the same before the paragraphs you want to indent. With code, I suppose it works differently. – Alenanno Oct 23 '12 at 16:42
  • @BoltClock Ok, thanks. That said, is it a reasonable feature request to ask that the "format as code" button automatically detect if you are in a list and therefore indent the code by 8 space instead of 4? Because that is the means by which I formatted the script to code (which did not work, until a preceded the code with a period). – n00b Oct 23 '12 at 16:42
  • @Alenanno: Sorry, I don't quite follow... – BoltClock's a Unicorn Oct 23 '12 at 16:48
  • @droid: It wouldn't hurt to ask! – BoltClock's a Unicorn Oct 23 '12 at 16:49
  • @BoltClock'saUnicorn Sorry I mixed but I meant that in normal lists, if you have (in vertical order): numbered item, normal paragraph, second numbered item. Then you need only 2 spaces for that paragraph to indent, not 4. If that paragraphs is a dot list, then even 0 spaces work. – Alenanno Oct 23 '12 at 16:52
  • @Alenanno: Ah yes, that's correct. It does work differently with code. If you look at my post, I have to indent my code by twelve spaces! This means for each level of nesting you have to add four spaces to the code block. – BoltClock's a Unicorn Oct 23 '12 at 16:54
  • @BoltClock'saUnicorn You indented 12 times? Quite tedious... That's why in such cases I choose alternative ways (screenshots of tables or graphs). :D – Alenanno Oct 23 '12 at 16:55
  • @Alenanno: Yeah, sometimes I'm tempted to do the same... but then I just highlight, copy and paste the indentation instead. – BoltClock's a Unicorn Oct 23 '12 at 16:56

You must log in to answer this question.

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