trentm / python-markdown2

markdown2: A fast and complete implementation of Markdown in Python
Other
2.66k stars 433 forks source link

Multiple fenced code blocks break them #580

Closed IncandescentChrysalis closed 5 months ago

IncandescentChrysalis commented 5 months ago

Describe the bug

Multiple fenced code blocks seem to pollute each other

To Reproduce

* List 1

code 1

code 2

code 3

Observed behavior

<ul>
<li>List 1
<pre><code>code 1

code 2</li>
</ul>

</code></pre>

<pre><code>code 3

<p></code></pre></p>

Expected behavior

<ul>
<li>List 1
<pre><code>code 1

code 2
</code></pre></li>
</ul>
<pre><code>code 3</code></pre>

Debug info

Version of library being used:

Extras used:

Additional context

Broken for nested lists too.

The following Markdown code:

* List 1
    * List 2
  code 1

  code 2
  ```
code 3
yields:
```HTML
<ul>
<li>List 1
<ul>
<li>List 2
<pre><code>code 1

code 2</li>
</ul></li>
</ul>

</code></pre>

<pre><code>code 3

<p></code></pre></p>

instead of:

<li>List 1
<ul>
<li>List 2
<pre><code>code 1

code 2
</code></pre></li>
</ul></li>
</ul>
<pre><code>code 3</code></pre>

All Markdown code cross-tested with the markdown-it demo.