AlertBlocks as children of non-MarkdownDocuments? #765

Closed
opened 2026-01-29 14:45:08 +00:00 by claunia · 3 comments
Owner

Originally created by @phil-scott-78 on GitHub (Dec 9, 2025).

I'm trying to use AlertBlocks - admittedly in a weird way - where they aren't direct children of a MarkdownDocument; I have them in a custom container block. In this scenario they aren't being rendered as Alerts but rather Quoteblocks.

This check in the AlertInlineParser is what is jamming me up. Just playing around and tweaking it so we are explicitly avoiding scenarios where we are in a nested QuoteBlock seems to be sufficient to the purpose, but I might be missing scenarios where we don't want alert blocks as children elsewhere too.

        if (processor.Block is not ParagraphBlock paragraphBlock ||
            paragraphBlock.Parent is not QuoteBlock quoteBlock ||
            paragraphBlock.Inline?.FirstChild != null ||
            quoteBlock is AlertBlock ||
            quoteBlock.Parent is QuoteBlock)
        {
            return false;
        }

Happy to submit a PR if I'm not overlooking anything and this is acceptable.

Originally created by @phil-scott-78 on GitHub (Dec 9, 2025). I'm trying to use AlertBlocks - admittedly in a weird way - where they aren't direct children of a MarkdownDocument; I have them in a custom container block. In this scenario they aren't being rendered as Alerts but rather Quoteblocks. This [check](https://github.com/xoofx/markdig/blob/cd7b9ca0ef66cb582232cbceaefbfe4195cf575b/src/Markdig/Extensions/Alerts/AlertInlineParser.cs#L43) in the `AlertInlineParser` is what is jamming me up. Just playing around and tweaking it so we are explicitly avoiding scenarios where we are in a nested QuoteBlock seems to be sufficient to the purpose, but I might be missing scenarios where we don't want alert blocks as children elsewhere too. ```csharp if (processor.Block is not ParagraphBlock paragraphBlock || paragraphBlock.Parent is not QuoteBlock quoteBlock || paragraphBlock.Inline?.FirstChild != null || quoteBlock is AlertBlock || quoteBlock.Parent is QuoteBlock) { return false; } ``` Happy to submit a PR if I'm not overlooking anything and this is acceptable.
Author
Owner

@MihaZupan commented on GitHub (Dec 9, 2025):

This is similar to #853.

https://github.com/xoofx/markdig/issues/853#issuecomment-2802969888

Note that this was an intentional change in https://github.com/xoofx/markdig/pull/842 to match GitHub's behavior where alerts must be top-level blocks.

An opt-in option that allowed it for nested containers could make sense here.

@MihaZupan commented on GitHub (Dec 9, 2025): This is similar to #853. https://github.com/xoofx/markdig/issues/853#issuecomment-2802969888 > Note that this was an intentional change in https://github.com/xoofx/markdig/pull/842 to match GitHub's behavior where alerts must be top-level blocks. An opt-in option that allowed it for nested containers could make sense here.
Author
Owner

@phil-scott-78 commented on GitHub (Dec 9, 2025):

An opt-in option that allowed it for nested containers could make sense here.

An opt-in option would be nice. I was gonna just swap out for a custom parser because my case is a bit out there, but I still need

 processor.ReplaceParentContainer(quoteBlock, alertBlock);

which is internal

@phil-scott-78 commented on GitHub (Dec 9, 2025): > An opt-in option that allowed it for nested containers could make sense here. An opt-in option would be nice. I was gonna just swap out for a custom parser because my case is a bit out there, but I still need ```csharp processor.ReplaceParentContainer(quoteBlock, alertBlock); ``` which is internal
Author
Owner

@phil-scott-78 commented on GitHub (Dec 10, 2025):

since this does seem to be a duplicate of #853, I'm gonna close it and move my comments over there

@phil-scott-78 commented on GitHub (Dec 10, 2025): since this does seem to be a duplicate of #853, I'm gonna close it and move my comments over there
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#765