0

I have encountered differences between python markdown and markedjs, when i switched from client-side to server-side rendering.

Consider the following markdown:

**bold text**
* list item 1
* list item 2
* list item 3

markedjs would gracefully create an unorder list html list from that:

<p>
  <strong>bold text</strong>
</p>
<ul>
  <li>item 1</li>
  <li>item 2</li>
  <li>item 3</li>
</ul>

while python-markdown creates:

<p>
  <strong>bold text</strong>
  <em> item1</em> item2
* item3
</p>

The problem here seems to be that python-markdown (following markdown.pl) wont accept the missing empty line and pulls the first list item into consideration with the bold tags...

Is there any way to configure python markdown to handle that case gracefully i.e. in a way a user would not be surprised by a weird html output?

Thanks in advance!

René Jahn
  • 1,155
  • 1
  • 10
  • 27

2 Answers2

1

The behavior of Python-Markdown in this case applies to the original from John Gruber (You can test it at the Markdown projects website). Probably you can write an extension for Python-Markdown to change the behavior.

You can also have a look at python-markdown2, they have an option to change the behavior of the parser to accept the list without a newline (cuddled lists):

import markdown2

md_text = "**bold text**
* list item 1
* list item 2
* list item 3"

md = markdown2.markdown(md_text, extras=['cuddled-lists'])
print(md)

This results in:

bold text

  • list item 1
  • list item 2
  • list item 3
rfkortekaas
  • 6,049
  • 2
  • 27
  • 34
0

Is there any way to configure python markdown to handle that case gracefully

You can write an extension. Python-Markdown's extension API provides access to the entire parser such that you can override any part of it. Therefore, if you wanted to change the bahavior such that a blank line was not required to start a list, you could replace the appropriate blockprocessors with your own.

Note that the Python-Markdown devs have expressly stated that they are not interested in supporting Commonmark. Therefore, any work to make Python-Markdown conform to Commonmark will need to be done as third party extensions.

Regarding the list items being recognized as emphasis, that is a bug, which I have just reported as issue #783. Thanks for bringing it to our attention.

Full disclosure: I am the lead developer of Python-Markdown.

Waylan
  • 37,164
  • 12
  • 83
  • 109