I was handling some bad Markdown input using Text::Markdown, when I saw it generate broken HTML.

I started with (bad) Markdown input " 1. z

>" and got back HTML <p><ol>

<li>z</p>



<blockquote>

<p></li>

</ol></p>

</blockquote> .

(See the incorrectly nested HTML tags, <p><ol><li></p> ?)

So I tried feeding this bad Markdown to four different Perl Markdown libraries: Text::Markdown, Text::MultiMarkdown, Text::Markdown::Discount, and Markdent, to see which one would give me valid HTML.

The results?

Text::Markdown — invalid HTML <p><ol>

<li>z</p>



<blockquote>

<p></li>

</ol></p>

</blockquote>



Text::MultiMarkdown — invalid HTML <p><ol>

<li>z</p>



<blockquote>

<p></li>

</ol></p>

</blockquote>



Text::Markdown::Discount — valid HTML! <ol>

<li> z



<blockquote></blockquote></li>

</ol>





Markdent — valid HTML, but doesn't generate a simple HTML fragment <!DOCTYPE html>

<html><head><title></title></head><body><ol><li>z

>

</li></ol></body></html>

The solution? Switch from Text::Markdown to Text::Markdown::Discount.