mixmark-io / turndown

🛏 An HTML to Markdown converter written in JavaScript
https://mixmark-io.github.io/turndown
MIT License
8.52k stars 864 forks source link

HTML nested lists are not formatted correctly in Markdown #450

Closed goodbomb closed 8 months ago

goodbomb commented 8 months ago

I have the following valid HTML:

<ol>
  <li>Item #1
      <ol>
          <li>Item #1 - Child 1
              <ol>
                  <li>Item #1 - Grandchild 1</li>
              </ol>
          </li>
      </ol>
  </li>
  <li>Item #2</li>
  <li>Item #3</li>
</ol>

However the output ends up being this:

1. Item #1
1. Item #1 - Child 1
1. Item #1 - Grandchild 1
2. Item #2
3. Item #3

There is no indentation to create the nested format for the list items. Is there some kind of setting I'm missing to properly convert this?

Any help would be appreciated. Thanks!

martincizek commented 8 months ago

Could it be that something ate your leading whitespace after turndown generated it correctly?

image
goodbomb commented 8 months ago

Hmm, good question. If you're saying it's working, then there must be something else going on. I'll dive deeper into my code and see what's up. I am using "prettier" on the HTML for debugging purposes before feeding it into turndown. Maybe that's impacting it. Thanks.

goodbomb commented 8 months ago

Yeah, that was it. I was accidentally beautifying the output, which stripped the leading whitespace.