-8

Sometimes, when I answer a question, I use a list to explain things and add some code after that, for example:

  • argument 1 is hoppa

  • argument 2 is klap

  • argument 3 is klap

    command hoppa klap klap

The command however is not formatted correctly on Stack Overflow. When I add a line between them (which basically does not mean anything)

  • argument 1 is hoppa
  • argument 2 is klap
  • argument 3 is klap

blah blah:

command hoppa klap klap

The code is formatted correctly.

Adding two spaces extra, will produce code that seems part of the last list item, which is not what is meant.

  • argument 1 is hoppa

  • argument 2 is klap

  • argument 3 is klap

    command hoppa klap klap
    

The question is closed with a referral to a completely different question: that of nesting code in a list. Also some comments point to that. This question is not about nesting code in a list. If you look at the accepted answer, you will also see that this is not the case.

  • 1
    You need an extra level of indent (4 space) for code block in a list. In you example 2 extra space will fix it ... – DavidPostill Jul 12 at 10:30
  • 7
    Duplicate of the faq post How to nest code within a list using Markdown. If this FAQ doesn’t apply to the current CommonMark parser, it should really be updated… – user289905 Jul 12 at 10:35
  • 1
    Not a bug - indented lines after a list item are continuations of the list item, so you either need to: indent further to put a code block in the list item; use a code fence to put code straight after a list; or otherwise explicitly end the list before adding an indented code block. – jonrsharpe Jul 12 at 10:48
  • @DavidPostill; @user289905 : no. that is not what I asked. – Ljm Dullaart Jul 12 at 10:55
  • @jonrsharpe: Ok. A code block instead of the four space indent works as well. I would, however have expected that an empty line after the list would explicitly end the list. – Ljm Dullaart Jul 12 at 11:00
  • @LjmDullaart I've added why that's not the case to my answer. – jonrsharpe Jul 12 at 11:10
  • Please research including googling the help center/FAQ & site:Meta Stack Exchange before considering asking a question. Why? – philipxy Jul 12 at 18:19
  • I did before posting, and I did also just now. All I can find are answers that would make the code part of the list-item which is, as I stated again and again, not the question, ans this answer. So please, instead of just saying "use google" enlighten me to what search-terms would produce the answer to the question. – Ljm Dullaart Jul 13 at 6:43
  • This question is a duplicate, of this answer on the question this is closed again: meta.stackexchange.com/a/7837/361484 – Luuklag Jul 13 at 6:56
5

This is intentional, and allows continuation paragraphs in list items, so this Markdown:

 - first

 - second 

    code block

Renders to:

  • first

  • second

    code block


Instead, use the code fence block style to add code right after a list, e.g. this:

 - first

 - second

```
code block
```

Renders to:

  • first

  • second

code block

Alternatively, note that you can explicitly (but invisibly) end the list with an empty comment:

 - first

 - second 

<!-- -->

    code block

Also renders to:

  • first

  • second

code block

As to why the blank line doesn't end the list, without the blank line the previous list item's paragraph is being continued:

 - list item
    New paragraph?

Renders to:

  • list item New paragraph?

This allows you to have long list items in places where you want to hard wrap the lines.

| improve this answer | |

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