Search code examples
githubmarkdowngithub-flavored-markdown

Correctly marking up multiple nested lists within the same list item


In a GitHub .md file, I'm trying to write the equivalent of:

<ul>
  <li>This is a list item</li>
  
  <li>This is also a list item
  
    <ul>
      <li>...containing a sublist</li>
      <li>with two items.</li>
    </ul>
    
    and then...
    
    <ul>
      <li>another sublist</li>
      <li>which also has two items</li>
    </ul>
  </li>
  
  <li>This is a third list item</li>
</ul>

I've tried numerous variations on:

 - This is a list item
 - This is also a list item
   - ...containing a sublist
   - with two items.
 
   and then...
 
   - another sublist
   - which also has two items
  - This is a third list item

but I've not yet found how to successfully nest multiple separate unordered lists within a single unordered list item.

How should I mark up the line and then... so that it (and every line after) renders correctly in GitHub-flavored markdown?


Solution

  • You can use fake bullet lists to achieve this. You can build them up using non-breaking spaces and a ⦁ (Z NOTATION SPOT) character.

     - This is a list item
     - This is also a list item&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;⦁&nbsp;&nbsp;...containing a sublist&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;⦁&nbsp;&nbsp;with two items.
     
       and then...
     
    &nbsp;&nbsp;&nbsp;⦁&nbsp;&nbsp;another sublist&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;⦁&nbsp;&nbsp;which also has two items
     - This is a third list item
    

    Result:

    • This is a list item

    • This is also a list item
      ⦁ ...containing a sublist
      ⦁ with two items.

      and then...

      ⦁ another sublist
      ⦁ which also has two items

    • This is a third list item