Lee Lee - 1 year ago 65
Markdown Question

markdown having multiple lists

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?

Answer Source

Bad Behavior - Concatenated lists:

(Marked and GitHub's) markdown have the behavior where lists separated by white-space are concatenated.

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 Behavior - Separated lists:

To get separate lists to render separately, separate your markdown lists with something that maps from markdown to HTML. These are invisible and work fine:

  • an HTML comment: <!-- -->
  • a line-break: <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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download