Python-Markdown / markdown

A Python implementation of John Gruber’s Markdown with Extension support.
https://python-markdown.github.io/
BSD 3-Clause "New" or "Revised" License
3.71k stars 856 forks source link

Trying to migrate from `markdown2`, lists without blank lines not working #1442

Closed nemecek-filip closed 6 months ago

nemecek-filip commented 6 months ago

Hello,

in my Django project I am using the other markdown package - I chose it back in 2021 without much thought. Currently I am working on migration to this one, but I have quite a lot of users' Markdown and these packages behave slightly differently when it comes to lists.

For example this:

Some random text
1.  Item 1
2. Item 2
3. Item 3

or:

Some random text
* Item 1
* Item 2
* Item 3

Does not render as a paragraph followed by list element. I also tried the "sane lists" extension. Unfortunately the markdown2 renders this correctly so I am looking for ways how to fix this in more elegant ways than giving my users opt-in upgrade path with instructions to re-check their rendered content.

Is there perhaps some extension or settings I could use to get the package to parse these lists if they immediately follow paragraph without new line? Or maybe reasonably easy custom extension that I would write would help me?

Thanks, appreciate any input!

facelessuser commented 6 months ago

Python Markdown normally requires blocks to have new lines before them. While occasionally, some blocks may work without this, it is generally recommended to use them before new blocks so they are not included in the block prior.

nemecek-filip commented 6 months ago

Do you think I could just add the new line with regex to the Markdown content before turning it into HTML with this package? Wouldn't this perhaps invite more problems?

waylan commented 6 months ago

Our behavior matches the behavior of the reference implementation. Therefore, it is markdown2 which has the behavior wrong. And for good reason. Consider this paragraph:

A sentence which makes mention of the year
2024. A year which has just gotten underway.

Clearly that should all be a single paragraph. It would be inappropriate to trigger a list just because the line wrapping happens to create what might look like a list item. The point is that Markdown can't tell the difference, so you should be required to insert a blank line if both lines are not part of the same paragraph.

If you want to go through your documents and automate the insertion of blank lines, you can. But how can you be certain you aren't splitting up a paragraph? I suppose because it would have been rendered that way to begin with it would at least be consistent.

In any event, I am closing this as wontfix.