This behavior is expected and is caused by our use of the CommonMark specification.
According to the CommonMark specification (Section 4.6 – HTML blocks), certain raw HTML blocks are terminated by a blank line. When a blank line appears inside one of these blocks, CommonMark treats it as the end of the block.
As a result, inserting blank lines between HTML elements can cause the parser to split the HTML into multiple blocks. Child elements may then be rendered outside of their intended parent element, producing unexpected or invalid HTML output.
This behavior is commonly encountered with elements such as <details>, <div>, and <table>, but can apply to other block-level HTML elements as well.
Recommendation
When using raw HTML in Markdown, do not include blank lines inside HTML blocks.
Ensure that all child elements appear directly after the opening tag and before the closing tag, without empty lines between them.
Example:
<details>
<summary>Expand</summary>
<ul>
<li>Item A</li>
</ul>
</details>