mixmark-io / turndown

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

fix #410 #411

Open FossPrime opened 2 years ago

FossPrime commented 2 years ago

Sandbox of this patch in action: https://stackblitz.com/edit/vitejs-vite-btuys7?file=main.js,index.html

Fix 410 by reducing the padding if the number of digits in the list grows. Also fixes issues with numbers over 99. Making the mid LI spacing adjustable is possible, but not part of this commit.

In deeply nested lists, indentation can still be broken for ordered lists over 99 nested inside other lists. A fix is difficult to implement without very very slow tree walking code.

This PR results in the following Screenshot from 2022-05-11 14-42-35

without the PR the paragraph would be misaligned like the following:

9.  This is a paragraph in a list item.

    This is a paragraph in the same list item as above.

10.  A paragraph in a second list item.

    This is a paragraph in the same list item as above.

Which github would correctly render as the following unexpected code_block:

  1. This is a paragraph in a list item.

    This is a paragraph in the same list item as above.

  2. A paragraph in a second list item.

    This is a paragraph in the same list item as above.