Skip to content

Enclosing fenced-code-blocks in a <div> tag renders incorrect HTML #481

@bow

Description

@bow

Hi maintainers

I have recently found a combination of raw HTML tag + Markdown (with fenced-code-blocks enabled) that I believed renders incorrectly.

Here is small test case that demonstrates the behavior.

Given the following markdown.md file:

<div class="enclosing">
```python
x = 1
```
</div>

and the following command

python lib/markdown2.py --extras fenced-code-blocks markdown.md

The following HTML is rendered:

<div class="enclosing">
<div class="codehilite">
<pre><span></span><code><span class="n">x</span> <span class="o">=</span> <span class="mi">1</span>
</code></pre>
</div>

<p></div></p>

Here, the final enclosing <div> becomes a part of a new <p> pair, leaving the outermost <div> with class "enclosing" unclosed.

The behavior I expected is to render this HTML:

<div class="enclosing">
<div class="codehilite">
<pre><span></span><code><span class="n">x</span> <span class="o">=</span> <span class="mi">1</span>
</code></pre>
</div>
</div>

In fact, this was actually the case up to version 2.4.3. I have not done a fully exhaustive search, but #462 seems to have introduced this behavior.

As additional info, I tested this with CPython 3.10.4, on a8bc182 using Pygments 2.13.0.


If no one has looked into this yet, I'd be happy to take a deeper dive and submit a PR 🙂.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions