Inconsistent HTML conversion using showdown npm when transforming Markdown to HTML and back—how can I preserve indentation structure?

HTML content:

<p>This is a heading</p>
<ul><li><p>This is a bullet point</p><ul><li>
<p>This is a sub bullet point</p>
</li></ul></li></ul>

Converted markdown content:

 'This is a headingn' +
     'n' +
     '* This is a bullet pointn' +
     '   * This is a sub bullet point'

Converted content from markdown back to HTML:

    n’ +

  • This is a bullet point
  • n’ +

  • This is a sub bullet point
  • n’ +

My Question:

  • Why is the conversion back to HTML from Markdown resulting in inconsistent formatting?
  • How can I preserve the original bullet point structure when converting between HTML and Markdown?
  • Are there any libraries or methods that handle this conversion more reliably?

Any guidance on how to maintain a consistent structure through these conversions would be greatly appreciated!