Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

markdown having multiple lists

Tags:

markdown

I had some html like this:

<ul>
    <li> 1 </li>
    <li> 2 </li>
</ul>
<ul>
    <li> a </li>
    <li> b </li>
</ul>

This HTML was generated using CKEditor, but I got fed up with WYSIWYGs and decided to use markdown instead.

I then converted it to markdown.

My markdown looks like:

- 1
- 2

- a
- b

However my output from my markdown is this:

 <ul>
        <li> 1 </li>
        <li> 2 </li>    
        <li> a </li>
        <li> b </li>
    </ul>

I need two separate lists as per the html prior to conversion. Can this be done?

like image 808
Lee Avatar asked May 23 '14 04:05

Lee


1 Answers

First I'll clarify the undesired behaviour, then I'll show you how to get the desired behaviour.

Undesired Behaviour - Concatenated Lists:

Markdown implementations often concatenate lists separated by whitespace.

For example, the following markdown has 5 lists

- a

- a
- b

- a
    - b


- a
    - b
- c


- a
    - b
        - c

and it renders as one big list:

  • a

  • a

  • b

  • a

    • b
  • a

    • b
  • c

  • a

    • b
      • c

Desired Behaviour - Separated lists:

To get separate lists to render separately, separate your markdown lists with something that maps from markdown to invisible HTML. Each of these work fine:

  • an HTML comment: <!-- -->
  • a linebreak: <br>
  • a non-breaking space: &nbsp;

Below are 4 markdown lists using each of them

- a

<!-- -->

- a
- b

<br>

- a
    - b

&nbsp;

- a
    - b
- c

which render as 4 separate lists:

  • a
  • a
  • b


  • a
    • b

 

  • a
    • b
  • c
like image 175
kdbanman Avatar answered Oct 22 '22 21:10

kdbanman