formatting nested list on github

1k Views Asked by At

Is there a way to notate which level a paragraph should belong to in a nested list on github?

- level 1 para 1
  - level 2 para 1   (trailing spaces added)
    level 2 para 2
  level 1 para 2

I wasn't able to get the above to work on github even though it rendered correctly on other markdown renderers. Anyone knows of a way to do so or is it a github bug?

1

There are 1 best solutions below

0
On

You need add blank lines between your paragraphs.

It is important to understand that when nesting items inside a list, the same syntax rules apply among those items. Therefore, let's take the "level 2" paragraphs. If you were to include those paragraphs at the document root, they would need to have a blank line separating them. Like this:

level 2 para 1

level 2 para 2

Therefore, when nesting them in a list, the same applies. Of course, you also need to indent to indicate that they are nested. Like this:

- level 2 para 1

  level 2 para 2

Now, if you were to include a paragraph before and after that list item, then you would do this (again, note the blank lines):

level 1 para 1

- level 2 para 1

  level 2 para 2

level 1 para 2

Of course, to nest all of that in a list item, you would need some additional indentation. However, you can't remove the blank lines just because the text is nested in a list item. Therefore, you need this:

- level 1 para 1

  - level 2 para 1

    level 2 para 2

  level 1 para 2

Finally, regarding your attempt to insert a linebreak (trailing spaces), that would (sort of) work between two paragraphs, but of course it would never work between a list item and a paragraph. As you at least need the blank lines between level 1 and level 2, you might as well include the blank lines within level 2 also.