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.76k stars 861 forks source link

InlineHTML <center> not treated as HTML correctly #1481

Open ScriptPup opened 1 week ago

ScriptPup commented 1 week ago

If <center> has tags nested underneath it, the <center> tag is surrounded by <p> tags, breaking the HTML.

from markdown import markdown
text = """# My Header

<center>
Test
</center>

<center>
<div>Something</div>
</center>

<div>
Test div
</div>

<div>
<p>Some paragraph</p>
</div>

<div>
<article>Some paragraph</article>
</div>

Something else
"""
print(markdown(text))

Results in:

image

It seems like

works correctly, so not 100% why the difference.

facelessuser commented 1 week ago

<center> should be treated as a block element (not wrapped in <p>). It's currently being treated as an inline element. It should also be noted that <center> is also a deprecated element that should not be used. With that said, since it is being used, maybe we should update the block element list to account for <center>.

waylan commented 1 week ago

Our behavior matches exactly the reference implementation (markdown.pl). Specifically, we treat <center> as an inline tag because the reference implementation does. As the tag is deprecated, I'm inclined to not make any changes.