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

<table> improperly wrapped by <p> when inside a list #1445

Closed socram8888 closed 6 months ago

socram8888 commented 6 months ago

When a <table> element is specified inside a list, it gets improperly wrapped with a <p>:

import markdown
html = markdown.markdown("""
  - List element

    <table></table>
""")
print(html)

Returns:

<ul>
<li>
<p>List element</p>
<p><table></table></p>
</li>
</ul>

This is not correct - tables are not allowed inside paragraph elements. What should be generated is:

<ul>
<li>
<p>List element</p>
<table></table>
</li>
</ul>
waylan commented 6 months ago

Please note that the syntax rules state regarding raw HTML:

The only restrictions are that block-level HTML elements — e.g. <div>, <table>, <pre>, <p>, etc. — must be separated from surrounding content by blank lines, and the start and end tags of the block should not be indented with tabs or spaces.

Of course, if they cannot be indented, then they cannot be nested inside list items. In fact, this same limitation exists in the reference implementation. We have no plans to change this behavior. However, one is certainly free to develop their own third-party extension which behaves differently.