trentm / trentm/python-markdown2

Markdown generates invalid markup

Open
#61 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.8k
Forks
459
Avg merge
2d 19h
Merged PRs (30d)
4

Description

The following snippet of text generates invalid markup:

* ABC
    * DEF

    *GHI

The result is (with @e417fd0 and the latest version from PyPI):

<ul>
<li><p>ABC</p>

<ul>
<li>DEF</li>
</ul>

<p><p>*GHI</p></li>
</ul></p>

Note that that second-to-last <p> tag is opened inside the <li> element, but closed outside the <ul>. This breaks my XML parser!

The source markup is not exactly clean (I am not even sure what the correct result would be) and is easily fixed by adding a space before "GHI". This still is an interesting case though, because it is genuine, non-technical user-input that I found in one of my wikis. As I parse the output of markdown2 as XHTML using ElementTree, this broke the rendering of the whole page...

Here is the result of parsing the same snippet with the "regular" markdown library:

<ul>
<li>
<ul>
<li>DEF</li>
</ul>
<p>ABC</p>
<p>*GHI</p>
</li>
</ul>

... and just for fun, here is what happens when GitHub parses it:

  • ABC

    • DEF

    *GHI

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the reported snippet through markdown2 and inspect the generated list markup against the regular Markdown output shown in the issue. Determine a valid XHTML structure for this input, then verify that the resulting output has properly nested and closed elements and can be parsed by ElementTree.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.