mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-10 21:40:00 +00:00
How to write custom Extension with nested elements #722
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Anton-Buzik on GitHub (Feb 12, 2025).
Hi, i have written an extension and this works fine until i have nested elements.
Currently i am struggling to understand how it should be implemented properly.
I see that my issue is how i take the content out and render it, but i dont understand how it should be done properly.
Many thanks for suggestions and help.
here is an working example: https://dotnetfiddle.net/TiTFJj
@xoofx commented on GitHub (Mar 13, 2025):
There are not so many inline parsers that support nested elements (with their own parsing/rendering rules). You would have to look at examples in the code inheriting from
IPostInlineProcessor(e.g.EmphasisInlineParser, orSmartyPantsInlineParser...) but none are easy to grasp. The idea is that you have to create pseudo-inline "marker" elements that delemit opening/closing duringInlineParser.Matchthat insert them into the syntax tree, and then you process them once the paragraph is done (viaIPostInlineProcessor.Process) and you recover opening/closing inlines, and replace them with proper inline containers. Unfortunately, it's not easy. You would have to dig into existing inline parsers that support this and figure this out.