27

If you have a list before you try to write code, your code doesn't get styled.

Am I doing something wrong?

  • Here's an example
  • Second item

    code->this.doesnt(work.at_all)

1
  • 4
    You need 8 whitespaces instead of 4 ;).
    – Tom
    Commented Jul 6, 2015 at 12:22

2 Answers 2

33

Use the suggested method mentioned in @Oded's answer if you want to format as code in the last item of the list.

If you want to format as code outside the list, insert a comment between the last item of the list and the code. Like:

  • List item 1
  • List item 2
code

Markdown for this example:

 - List item 1
 - List item 2

<!-- Comment inserted to render code *outside* the list -->

    code

You can also use an empty comment, i.e, <!---->

4
  • You can also use </> or </ (not sure if the second one would cause more issues in some cases, though)
    – Rob Mod
    Commented Jan 12, 2017 at 3:49
  • @Rob Are those valid HTML comments? I remember one time when I thought that <!> is a valid HTML comment and used it when required and the parser once got confused and misinterpreted stuff.
    – Spikatrix
    Commented Jan 13, 2017 at 12:37
  • This doesn't indent the code section as if it was part of the list item.
    – mins
    Commented Jan 4 at 11:27
  • 1
    @mins Yes, it doesn't. Check out @Oded's answer if you want the codeblock as part of the list item
    – Spikatrix
    Commented Jan 4 at 14:57
22

For code in lists to be interpreted as code, it needs to be indented 4 spaces further to the list indentation.

  • Here's an example
  • Second item

    code->this.does(work.just_fine)
    

This is also noted in the editing help for advanced lists (pretty much the very last line of that).

1
  • 1
    That way the code is visually associated to the last item (the code starts at the baseline of the item, not the baseline of text). What if I want to add code after the list, but don't want it to "belong" to the last item? I used to insert a line containing only e.g. a dot, and then add the code, but this isn't really nice either.
    – hbaderts
    Commented Jul 6, 2015 at 12:38

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