markdig icon indicating copy to clipboard operation
markdig copied to clipboard

[Question] Custom renderer outside MarkDig possible?

Open Seikilos opened this issue 7 months ago • 1 comments

Hi,

due to a lack of documentation I am trying to create a simple PDF exporter and was playing around with deriving from RendererBase because I won't return a text writer, so I cannot use TextRenderBase like the HtmlRenderer does. (This is my assumption)

However, the signature of render base poses some questions for me:

public override object Render(MarkdownObject markdownObject)

I get a MarkdownObject and need to descend down to containers, etc but I am stuck.

Beside the fact that I haven't found a way for a hierarchical traversal yet, I stumbled upon MarkdownObject.IsContainerInline and MarkdownObject.IsContainerBlock, which are internal.

I assume that I misunderstand how to approach the traversal, but does the internal modifier on the method above makes it quite tricky to discern what to do?

I looked at the plain text and html renderers, I also looked at some forked Wpf Renderer but still am unsure on how to handle traversal that way without a text render output (otherwise I could somehow hijack the html renderer I assume.

Or would be actually using the Html renderer to get html be the best way? I could parse the resulting html into a tree and then continue my pdf export from html instead of markdown I assume.

Seikilos avatar May 10 '25 07:05 Seikilos

RendererBase has several methods WriteChildren and Write(MarkdownObject) that are used to traverse the objects.

Your derived MarkdownObjectRenderer will call back to these methods as it is done for the HtmlRenderers For example for the list renderer here or the quote block renderer here ...etc.

xoofx avatar May 10 '25 16:05 xoofx