xoofx / markdig

A fast, powerful, CommonMark compliant, extensible Markdown processor for .NET
BSD 2-Clause "Simplified" License
4.21k stars 444 forks source link

AlertBlock content not rending properly #780

Closed jorge-moreira closed 4 months ago

jorge-moreira commented 4 months ago

Hi,

I was trying the new version and it seems that the paragraphs within the AlertBlock are not being rendered.

How to reproduce

Markdown example

> [!NOTE]
> Highlights information that users should take into account, even when skimming.
> 
> Testing rendering for multiple lines
> 
> `Inline code testing`
> 
> Other line
> 
> > Nested quote
> >
> > Final nested quote line
> 
> Final line of alert

Expected:

[!NOTE] Highlights information that users should take into account, even when skimming.

Testing rendering for multiple lines

Inline code testing

Other line

Nested quote

Final nested quote line

Final line of alert

HTML rendered result

<div class="markdown-alert markdown-alert-note">
<p class="markdown-alert-title"><svg viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"></path></svg>Note</p>
<p>Highlights information that users should take into account, even when skimming.</p>
<p></p>
<p></p>
<p></p>
<blockquote>
<p></p>
<p></p>
</blockquote>
<p></p>
</div>

When debugging, I noticed that the paragraph block, when was being rendered, the ContainerInline is null, and that way, the paragraph is not rendered: image

xoofx commented 4 months ago

Thanks for the repro, indeed, it's not working at all 😅

The issue is in ProcessInlines.ProcessInlines that maintain the stack of the blocks being processed, as we are changing from an inline expansion the parent block, the loop doesn't pick-up the new parent, and as we removed all children from the QuoteBlock (replaced by an AlertBlock), then it exits the loop (and doesn't process the AlertBlock because it is not in the stack of the element being processed by the loop)

Gonna have to think about how to proceed. e.g It might not be a good idea to change the structure of blocks while parsing inlines, so I might have to remove AlertBlock and add attributes to the QuoteBlock.

xoofx commented 4 months ago

Temporary fix 6549d3b726b32146f3025204abb3bfeec53e3c1c until this is revisited. The fix is not ideal, so for now I kept the code internal.

jorge-moreira commented 4 months ago

Temporary fix 6549d3b until this is revisited. The fix is not ideal, so for now I kept the code internal.

I'll also take a look into it. Thank you once again 🙇