Strange P tag behavior in lists

I found strange behavior of the P tag in lists.

If the list consists only of items, then the items are not wrapped with the P tag, but if there is a paragraph in the list, then each top-level item in this section is wrapped with the P tag.

For example

## Head 1
* List item
    * List item
* Long List item
    * List item

    Additional paragraph
## Head 2
* List item
    * List item
* List item
    * List item
<h2 id="head-1">Head 1</h2>
<ul>
    <li>
        <p>List item</p>
        <ul>
            <li>List item</li>
        </ul>
    </li>
    <li>
        <p>Long List item</p>
        <ul>
            <li>List item</li>
        </ul>
        <p>Additional paragraph</p>
    </li>
</ul>
<h2 id="head-2">Head 2</h2>
<ul>
    <li>List item
        <ul>
            <li>List item</li>
        </ul>
    </li>
    <li>List item
        <ul>
            <li>List item</li>
        </ul>
    </li>
</ul>

Is this a bug or I don’t understand how to format the source text correctly so that there are no extra tags?

Thank you.

This is doing exactly what it should be doing per the CommonMark specification.

Try it.

1 Like